Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TextToolbar - Switch Format from Custom Formatter #1514

Conversation

WilliamABradley
Copy link
Contributor

Fix for #1449.

-Added Two Way Binding to Format Property.

-Added new Reset Layout Command, Defaults the Toolbar to Default Configuration.

-You can now Clear the Custom Buttons ButtonMap.

-Added new Reset Layout Command, Defaults the Toolbar to Default Configuration.

-You can now Clear the Custom Buttons ButtonMap.
@WilliamABradley
Copy link
Contributor Author

@nmetulev @michael-hawker I now have two way binding, but it doesn't seem to update the ComboBox UI. Is there a Shell command or something to update the properties of a Binding from code behind?

nmetulev
nmetulev previously approved these changes Oct 3, 2017
@nmetulev nmetulev dismissed their stale review October 3, 2017 21:57

Found a way to update ComboBox UI

@nmetulev
Copy link
Contributor

nmetulev commented Oct 3, 2017

@WilliamABradley, there are two things that need to be done to get the ComboBoxUI to work.

  1. First, there is a bug in the sample app that needs to be fixed. It's a very small fix, so I think it can be included here. The EnumConverter convert method needs to make sure it is returning a string. Adding .ToString() on value should do it.

  2. In your method for using Custom Formatter, make sure you are actually updating the baking property for the binding instead of directly changing the Format on the control. To do this, you need to get a reference to the ValueHolder for the property. Here is the code that should do it:

    private void UseCustomFormatter()
    {
        if (_toolbar == null)
        {
            return;
        }
    
        var sample = DataContext as Sample;
        var properties = sample.PropertyDescriptor.Expando as System.Collections.Generic.IDictionary<string, object>;
        if (properties.TryGetValue("Format", out var format))
        {
            var formatter = new SampleFormatter(_toolbar);
            (format as Models.ValueHolder).Value = UI.Controls.TextToolbarFormats.Format.Custom;
            _toolbar.Formatter = formatter;
        }
    }
    
    

Once you do this, the behavior you are after will work. However, because properties are remembered from sample to sample, there is an exception that is thrown when you you navigate to the sample again after setting the Format to Custom. Steps to reproduce (after doing the above changes):

  1. Navigate to the TextToolbar sample
  2. Hit the Use Custom Formatter command
  3. Navigate back from the sample
  4. Navigate to the sample again (notice Format will be remembered as Custom)
  5. Hit Reset Layout. This will throw an exception (that is handled by the app)

Not sure if this is an issue with the sample or the control itself, but it should be looked at.

@nmetulev nmetulev added this to the v2.1 milestone Oct 3, 2017
@nmetulev
Copy link
Contributor

nmetulev commented Oct 9, 2017

@WilliamABradley, up?

@nmetulev
Copy link
Contributor

Up?

@WilliamABradley
Copy link
Contributor Author

I'll see if I can do this later today

-Fixed Custom Formatter not being initialised when returning to the sample after Navigation.
@WilliamABradley
Copy link
Contributor Author

@nmetulev All done :)

Copy link
Contributor

@nmetulev nmetulev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works as advertised :)

{
get
{
var sample = DataContext as Sample;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to check for null here unless you're sure then (cast) don't (as).
Same thing for the if(properties.TryGetValue), properties could be null because of the as.

-Added some Pattern Matching.
@WilliamABradley
Copy link
Contributor Author

@IbraheemOsama Added some Null Safeties.

@IbraheemOsama
Copy link
Member

@WilliamABradley perfect :)

@IbraheemOsama IbraheemOsama merged commit a520062 into CommunityToolkit:master Oct 29, 2017
@WilliamABradley WilliamABradley deleted the TextToolbar-CustomFormatterButtonFix branch October 29, 2017 05:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants