Hi,
I apologise in advance for what's probably a simple WPF data binding question.
I'm trying to bind the AllowEdit field setting on the XamDataGrid to some property on my control's data context, but I can't find the right syntax. What I've got is something like the following:
<UserControl>
<XamDataGrid>
<DataPresenter:XamDataGrid.FieldSettings>
<DataPresenter:FieldSettings AllowEdit="{Binding MyAllowEdit}" />
</DataPresenter:XamDataGrid.FieldSettings>
...
</XamDataGrid>
</UserControl>
Where MyAllowEdit is a property on the object that is the DataContext of my User Control.
I've tried a number of different bindings, but I just can't figure out how to do it.
Cheers,
Adam
Hello Adam,
You are most likely not getting change notification because the FieldSettings object is not part of the Visual Tree. In circumstances like this, I typically suggest that people handle the PropertyChanged event of their DataContext on their Window or UserControl and set the property manually:
void myDataContext_PropertyChanged(object sender, PropertyChangedEventArgs e) { if (e.PropertyName == "MyAllowEdit") { //check new value and apply settings to the grid } }
Hope that helps.
Thanks for the answer. At the moment, we don't actually need to listen for changes, so I'm just setting the value when the screen loads. The main reason that I was trying to use the binding was because I was trying to do as much as possible in XAML and avoid the code behind if possible.
Is there any other way to set this value from XAML (to the value in the DataContext)?