I have several ComboBoxes in a DataForm and am trying to have it so that certain ComboBoxes are disabled until a particular ComboBox is selected. To this end, I created a notification property named CanEditCombo in the class that is bound to the DataContext and configured my ComboBoxes like so:
<ComboBox ... IsEnabled="{Binding CanEditCombo, Mode=OneWay}" />
The CanEditCombo is initially false, yet my ComboBoxes are editable when the DataForm first loads.
If I apply the same IsEnabled binding syntax to a TextBox in my DataForm it works as expected: disabled at first but enabled once CanEditCombo becomes true.
Here is an example chunk of XAML:
<toolkit:DataForm CurrentItem="{Binding NewProject, Mode=TwoWay}" x:Name="dfNewProject" CommandButtonsVisibility="None">
<toolkit:DataForm.EditTemplate>
<DataTemplate>
<StackPanel>
...
<toolkit:DataField>
<ComboBox ItemsSource="{Binding ProjectOptions, Mode=OneWay}"
SelectedValue="{Binding Options, Mode=TwoWay}"
DisplayMemberPath="Value"
SelectedValuePath="Key"
IsEnabled="{Binding CanEditCombo, Mode=OneWay}" />
</toolkit:DataField>
...
</StackPanel>
</DataTemplate>
</toolkit:DataForm.EditTemplate>
</toolkit:DataForm>
What’s more, even if I hard-code the ComboBox’s IsEnabled property to False in the markup above the ComboBox is still editable.
How do I go about having the ComboBox’s IsEnable property set via binding syntax when the ComboBox is in a DataForm?
Not sure if you’ve discovered the answer to this yet, but there’s actually a really simple solution: set IsEnabled on the DataField rather than the ComboBox (or any other DataField nested control).
I’m not sure exactly what the DataField is doing internally but the IsEnabled property never gets accessed on a nested control.