I need to be able to make a XamDataGrid XamComboEditor read only in mvvm way through binding to a boolean property in a view model. I cant seem to get this to work by simple binding AllowUpdate to this boolean field in FieldSettings, for some reason the field drop down remains active if I bind it to a view model boolean variable. However if I just set AllowUpdate ="False" the field is disabled. Here is my code:
<igDP:Field Label="F1" Name="F1"> <igDP:Field.Settings> <igDP:FieldSettings AllowEdit="{Binding IsEnabled}" EditorType="{x:Type igEditors:XamComboEditor}"> <igDP:FieldSettings.EditorStyle> </igDP:FieldSettings.EditorStyle> </igDP:FieldSettings> </igDP:Field.Settings></igDP:Field>
Hello Andre,
Thank you for your feedback. I am glad that you resolved your issue and I believe that other community members may benefit from this as well.
Thanks again.
Thanks, that worked great!
If you want each Record to have different edit settings you can set the XamComboEditor’s IsEnabled Property like this:
<Setter Property="IsEnabled" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type igDP:DataRecordPresenter}},Path=Record.DataItem.IsEnabled}"/>
Or you can use a converter and set the Editor’s IsReadOnly Property. Please let me know if this helps you or you need further assistance on this matter.
Looking forward for your reply.
Stefan, thank for the sample unfortunately IsEnabled isn't an ViewModel property - rather its a property of the Model in OvservableCollection that I'm binding to the grid. Therefore, for each row in the grid I have this property accessible via DataItem.IsEnabled. In other words, for every row in the grid I want to either enable or disable this cell based on this boolean variable value in the Model associated with the row. What should my binding be in that case? Thanks.
Something like this -
Model:
public class Model
{
public int Id{get; set;}
public String Name{get; set;}
public bool IsEnabled{get; set;}
}
In View Model:
public ObservableCollection<Model> mdlList = new ObservableCollection<Model>();
public ObservableCollection<Model> MDList{get{return mdList;}}
In Xaml:
<UserControl ... DataContext="{Binding MyViewModel, Source={StaticResource Locator}}">
<igDP:XamDataGrid x:Name="xamDataGrid" DataSource="{Binding MDList}"...
<igDP:Field Label="Field" > <igDP:Field.Settings> <igDP:FieldSettings AllowEdit="{Binding Source={StaticResource Locator},Path=DataItem.IsEnabled}" EditorType="{x:Type igEditors:XamComboEditor}"> <igDP:FieldSettings.EditorStyle> <Style TargetType="{x:Type igEditors:XamComboEditor}"> <Setter Property="ItemsSource" Value="{Binding DataItem.Vals, UpdateSourceTrigger=PropertyChanged}"/> <Setter Property="DisplayMemberPath" Value="Name" /> </Style> </igDP:FieldSettings.EditorStyle> </igDP:FieldSettings> </igDP:Field.Settings> </igDP:Field>
I have been looking into the code you have shared and I can say that since the Grid’s Resources are not part of the visual tree, neither, the Bindings inside should also has Source. I noticed that you already have a StaticResource (Locator), which you can use in the AllowEdit Binding. I can suggest you try the following binding there:
<igDP:FieldSettings AllowEdit="{Binding Source={StaticResource Locator},Path=MyViewModel.IsEnabled}"/>
Please let me know if this helps you or you need further assistance on this matter.