Wiring up Visibility Convention for Button

Topics: Conventions
Nov 14, 2011 at 11:03 PM

Evening everyone!

I am trying to put a convention together to wire up the Visibility on a button. Specifically a RadRadioButton but if I could get it to work on a regular button then it should work as well. All I want to do is to add an extra convention so that just like the CanXXXX guard.. I could also have visibility items hooked up on demand. Currently the code below is what I am working with but it never seems to get called.

I put logging statements in it to try and see if and where it gets bound. The only times I can see it being called up is when I use something like

public bool MyButton {get;set;}  

It's almost like it only gets called when the other visibility convention is triggered.... Hmmmm :( 


Any help is much appreciated!

 ConventionManager.AddElementConvention<RadRadioButton>(RadRadioButton.VisibilityProperty, "DataContext", "LeftMouseButtonUp")
                .ApplyBinding = (viewModelType, path, property, element, convention) =>
                    if (!ConventionManager.HasBinding(element, RadRadioButton.VisibilityProperty))
                        var index = path.LastIndexOf('.');
                        index = index == -1 ? 0 : index + 1;
                        var baseName = path.Substring(index);
                        foreach (var potentialName in DerivePotentialVisibilityNames(baseName))
                            if (viewModelType.GetPropertyCaseInsensitive(potentialName) != null)
                                var selectionPath = path.Replace(baseName, potentialName);
                                var binding = new Binding(selectionPath) { Mode = BindingMode.TwoWay,
                                Converter = ConventionManager.BooleanToVisibilityConverter};

                                BindingOperations.SetBinding(element, RadRadioButton.VisibilityProperty, binding);


                    return true;