This project has moved. For the latest updates, please go here.

PropertyGrid and UpdateSourceTrigger=PropertyChanged not working

Jun 3, 2015 at 1:13 PM
Edited Jun 3, 2015 at 1:14 PM

I got a grid with the following binding:
<tk:PropertyGrid  SelectedObject="{Binding Blubber, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True, ValidatesOnExceptions=True}" >
in the "Blubber" class I have a public property that throws an exception:

private string validationTest = "hello";
    public string ValidationTest
            return validationTest; 


            if (value != "hello") throw new MyValidiationException("Must be hello");
            else validationTest = value; 
Now when I enter some text in the PropertyGrid, the UpdateSourceTrigger=PropertyChanged should update the binding immediately while typeing. So the exception should be thrown immediately. Yet it doesn't!

Is this a bug or does anyone have an explanation for it?
Jun 3, 2015 at 6:32 PM

The Binding is on the SelectedObject, so UpdateSourceTrigger will be activated when the SelectedObject changes. But here, its a property from the SelectedObject that is changed. Here's what you could do :
 <xctk:PropertyGrid x:Name="_propertyGrid"
                            SelectedObject="{Binding Blubber}">
               <xctk:EditorTemplateDefinition TargetProperties="ValidationTest">
                          <!-- one option -->
                          <!--<TextBox Text="{Binding Value, UpdateSourceTrigger=PropertyChanged}" />-->
                          <!-- another option -->
                          <xctk:PropertyGridEditorTextBox Text="{Binding Value, UpdateSourceTrigger=PropertyChanged}" />
Jun 8, 2015 at 12:04 PM

Thanks for your reply. Using the proposed template definition it's working fine. For those who might want to apply it to not only named properties, but based on the type of the property:
                <tk:EditorTemplateDefinition >
                        <tk:TargetPropertyType Type="{x:Type s:Int32}" />
                        <tk:TargetPropertyType Type="{x:Type s:String}" />
                            <tk:PropertyGridEditorTextBox Text="{Binding Value, UpdateSourceTrigger=PropertyChanged}" />
Thx again