Dynamic Binding of Property to PropertyStatus Causes PropertyStatus Not to Show

Dynamic Binding of Property to PropertyStatus Causes PropertyStatus Not to Show

Old forum URL: forums.lhotka.net/forums/t/11441.aspx


Nitronie posted on Thursday, June 28, 2012

Hey,

I'm developing a form to edit the properties of one of my Business Objects in Silverlight, and since each property is displayed for editing much the same way, I was trying to make the job easier by making a custom UserControl that would display the FriendlyName in a TextBlock, the actual String in the property in a TextEdit (using DevExpress control, but I assume this is the same name for normal TextBoxes), and then a PropertyStatus for the Property next to the TextEdit. 

I got this working with TwoWay Binding on the form, but when I tried to pull it out into a seperate UserControl for DRY, only the PropertyStatus is not updating and showing the error. I know it has the error, because when I debugged it and hovered over the name of the PropertyStatus in the code-behind it showed that the object had correctly picked up the error, it just wasn't displaying it. 

I'm using the following code to accomplish this:

 

Since I was having problems binding the property to the different UserControls in the XAML, I pulled it into the code behind using the following method:

 

public void SetupBindings(Csla.PropertyInfo<String> property, Object dataContext)

        {

            this.propertyNameLabel.Text = property.FriendlyName + ":";

 

            //set up binding object

            Binding b = new Binding();

            b.Path = new PropertyPath(property.Name);

            b.Mode = BindingMode.TwoWay;

            b.Source = dataContext;

 

            this.propertyNamePropertyStatus.SetBinding(Csla.Xaml.PropertyStatus.PropertyProperty, b);

            this.propertyNameTextEditor.SetBinding(DevExpress.Xpf.Editors.TextEdit.TextProperty, b);

        }

 

 

 

Then the form (the parent of the custom control) calls the method like this:

 

public FormView()

        {

            InitializeComponent();  

            this.DataContextChanged += new DependencyPropertyChangedEventHandler(FormView_DataContextChanged);

        }

 

void FormView_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)

        {

            this.propertyTextEditorControl.SetupBindings(

               MyCslaLibrary.MyObject.MyPropertyProperty, this.DataContext);

        }

 

 

The DevExpress TextEdit will display the Validation Error just fine, but I don't like the way it does, and it doesn't display warning, information, and busy status, so I'd really rather use the PropertyStatus control, but it's not working. Please help.

 

Copyright (c) Marimer LLC