I want to bind AllowAddNew and AllowDelete in the FieldLayout Settings because their true/false values will depend on some values, say AllowEditData in the VM.
Any suggestions?
Hello InfraNewbie,
Unfortunately, it is not currently possible to 'directly' bind to a path in your ViewModel from the FieldLayoutSettings object. This is because the FieldLayoutSettings element does not derive from FrameworkElement and so does not expose a DataContext property, and so a direct Binding path will not work here - you will need a source.
The best recommendation I can make in this case is to bring your ViewModel into your XAML as a keyed resource. In doing so, you can set up a binding like the following, where "AllowAddNew" is a bool property on the ViewModel, which has a key of "VM" in this case:
AllowAddNew="{Binding Source={StaticResource VM} Path=AllowAddNew}"
I have attached a sample project to demonstrate the above. I hope this helps.
Please let me know if you have any other questions or concerns on this matter.
Sincerely,AndrewAssociate Developer
This approach does not work for me since I cannot set keyed resource for my ViewModel as it does not have a default constructor. As a matter of fact, its construction requires many parameters.
<local:ViewModel x:Key="VM"/
You are correct on this, a non-default constructor for your ViewModel does unfortunately make my original recommendation in this case unusable.
Still, it remains that you cannot directly bind properties that exist on the FieldLayoutSettings or FieldSettings of the XamDataGrid, and so my new recommendation is to create a custom, derived XamDataGrid with a DependencyProperty for each of the properties that you wish to bind. By hooking up a property changed callback to them, you can apply the new value to the underlying XamDataGrid.FieldSettings.PropertyName or XamDataGrid.FieldLayoutSettings.PropertyName programmatically, making these new properties act as a sort of "bridge" to the underlying FieldSettings and FieldLayoutSettings.
I have attached a modified version of the original sample project I sent to demonstrate the above. I hope this helps.
Thanks for your help.