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
I am having the same problem. I have a UserControl that hosts a XamDataGrid. I have a dependency property IsEditable that can be set on the UserControl. Based on the value of this property, I want to set AllowEdit to true or false. I have tried the following and I get the same error as mentioned above. Does anyone have a solution for this?
<igDP:FieldSettings CellWidth="25" LabelWidth="25"
AllowEdit="{Binding ElementName=ROTabGridUserControl,Path=IsEditable}"
EditorType="{x:Type igEditors:XamNumericEditor}"
EditorStyle="{StaticResource PercentageEditorStyle}"
/>
</igDP:UnboundField.Settings>
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; }}