1
votes

In the application I am working on, if the user is not a Admin, he must not be allowed to the change the data. But he must still be able to have readonly access to the data.

If I disabled the grid itself, I cannot scroll through the records and I cannot use the built-in filtering feature of the infragistics XamDataGrid. What I want to achieve is to disabled only the rows of the datagrid, so that it is in a state of readonly.

In the ViewModel, I have a boolean property named IsAdmin.

    private bool _isAdmin;
    public bool IsAdmin
    {
        get { return _isAdmin; }
        set { SetProperty(ref _isAdmin, value); }
    }

In the View I have the declaration of the XamDataGrid

<igDP:XamDataGrid x:Name="LookupItems" Grid.Row="2" Grid.ColumnSpan="3" Margin="2,4" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" BorderBrush="Black" 
                          BorderThickness="1" Theme="Office2010Blue" ActiveDataItem="{Binding SelectedLookupItem}" DataSource="{Binding SelectedLookupTableLookupItems}" >

            <igDP:XamDataGrid.InputBindings>
                <KeyBinding Key="Del" Command="{Binding DeleteItemCommand}" />
            </igDP:XamDataGrid.InputBindings>

            <igDP:XamDataGrid.FieldLayoutSettings>
                <igDP:FieldLayoutSettings AllowDelete="True" HighlightAlternateRecords="True" AllowAddNew="True" AutoArrangeCells="LeftToRight"  
                                          ResizingMode="Immediate" SelectionTypeRecord="Single" AutoGenerateFields="False" />
            </igDP:XamDataGrid.FieldLayoutSettings>

            <igDP:XamDataGrid.FieldSettings>
                <igDP:FieldSettings AllowRecordFiltering="True" AllowGroupBy="False" />
            </igDP:XamDataGrid.FieldSettings>

            <igDP:XamDataGrid.FieldLayouts>
                <igDP:FieldLayout>
                    <igDP:FieldLayout.Fields>

                        <igDP:Field Name="ConvertFrom" Label="From" AllowEdit="True" Width="*" 
                                    IsEnabled="{Binding Path=DataContext.IsAdmin, RelativeSource={RelativeSource AncestorType={x:Type igDP:XamDataGrid}}}" >
                            <igDP:Field.Settings>
                                <igDP:FieldSettings FilterOperandUIType="TextBox" FilterOperatorDefaultValue="Contains" />
                            </igDP:Field.Settings>
                        </igDP:Field>

                        <igDP:Field Name="ConvertTo" Label="To" AllowEdit="True" Width="*" AllowRecordFiltering="False" 
                                    IsEnabled="{Binding Path=DataContext.IsAdmin, RelativeSource={RelativeSource AncestorType={x:Type igDP:XamDataGrid}}}">
                        </igDP:Field>

                    </igDP:FieldLayout.Fields>
                </igDP:FieldLayout>
            </igDP:XamDataGrid.FieldLayouts>
        </igDP:XamDataGrid>

The problem I have is that the field on the datagrid doesn't get disabled. I know that my property is working because I have others controls on the page (Textbox, ComboBox, Checkbox, etc...) that are disabled when the IsAdmin property is set to false.

Is there something wrong with my binding in the datagrid? I can't figure out what is the problem.

1

1 Answers

1
votes

You should be using the FieldBinding markup extension

http://help.infragistics.com/doc/WPF/2016.1/CLR4.0/?page=xamDataGrid_Binding_Field_FieldLayout_to_MVVM.html

<igDP:MaskedTextField Name="SKU" 
    Mask="########-###"
    Label="{igDP:FieldBinding SelectedRole.RoleSettings[SKU].ColumnName}" 
    IsReadOnly="{igDP:FieldBinding SelectedRole.RoleSettings[SKU].IsColumnReadOnly}"/>