We are trying to develop a grid whose AllowEdit property for field settigs depends on some runtime values. It seems that almost any kind of binding fails. We have tried:
AllowEdit="{Binding ElementName=parentUserControlName, Path=IsEditAllowed} "
and
AllowEdit="{Binding IsEditAllowed}" after setting the User Control's DataContext to "this".
Both times we get the error:
System.Windows.Data Error: 2 : Cannot find governing FrameworkElement or FrameworkContentElement for target element. BindingExpression:Path=IsEditAllowed; DataItem=null; target element is 'FieldSettings' (HashCode=15935451); target property is 'AllowEdit' (type 'Nullable`1')
However, if we set the Binding Source to be an x:Static, it works. For example:
AllowEdit="{Binding Path=IsEditAllowed, Source={x:Static Sample:EntitlementsProvider.Instance}}" it works fine!!!
I know that FieldSettings is just a DependencyObject, not a framework element, but if anyone could explain why this is happening and what workarounds we can do to dynamically set the AllowEdit property in a consistent and extensible manner, please let me know.
Thanks,
-Szymon
Hi,
Is this still a limitation in VS2013 ?
We need help in binding a viewmodel property to Allowedit in xaml. we tried in way as below, which is not working.
<igDP:Field.Settings>
<igDP:FieldSettings EditorType="{x:Type igEditors:XamCheckEditor}"
EditAsType="{x:Type sys:Boolean}"
SupportDataErrorInfo="False"
AllowRecordFiltering="False"
AllowEdit= "{Binding Path= ValidateUserRights}" />
</igDP:Field.Settings>
Here ValidateUserRights is a property in viewmodel as below
public bool ValidateUserRights {
get
{
return _ValidateUserRights;
}
private set
_ValidateUserRights =false;
We stuck here, Please help us to resolve it.
Yes this is still the case. Unfortunately this is a current limitation of WPF. The DataContext is only available on certain objects (e.g. FrameworkElement and elements which have an inheritance context). Unfortunately the inheritance context infrastructure within WPF is internal so we cannot access it. I would recommend rating the suggestion for adding support for this on MS' site here.
Is this still the case in the latest version? You can't simply do something like...
<igDP:Field Name="Price"> <igDP:Field.Settings> <igDP:FieldSettings LabelWidth="60" CellWidth="60" AllowEdit="{Binding Path=IsEditAllowed}"></igDP:FieldSettings> </igDP:Field.Settings> </igDP:Field>
Thank you. This is what I ended up doing. I was just hoping there was a way to do it in the xaml.
void xamDataGrid_factDefinition_FieldLayoutInitialized(object sender, FieldLayoutInitializedEventArgs e){ for (int i = 0; i < e.FieldLayout.Fields.Count; i++) { e.FieldLayout.Fields[i].Settings.AllowEdit = IsEditable; }}