禁用XamGrid中的单元格编辑

时间:2016-05-09 06:00:23

标签: wpf xaml mvvm infragistics xamgrid

我正在使用 DataTable 绑定 XamGrid 。我希望在特定条件下 禁用单元格的编辑 。我创建了 XamGrid 的行为。

可以根据我的要求提出解决方案吗?

3 个答案:

答案 0 :(得分:2)

尝试使用数据触发器定义样式:

        <igWPF:XamDataGrid.Resources>

        ...
        <Style TargetType="CellValuePresenter">
            <Style.Triggers>
                <!--one condition based trigger - condition is inside the cell data context-->
                <DataTrigger Binding="{Binding Path=DataItem.ConditionA}" Value="True">
                    <Setter Property="IsEnabled" Value="False"/>
                </DataTrigger>
                <!--multiple condition based trigger - condition is inside the cell data context-->
                <MultiDataTrigger>
                    <MultiDataTrigger.Conditions>
                        <Condition Binding="{Binding Path=DataItem.ConditionA}" Value="True" />
                        <Condition Binding="{Binding Path=DataItem.ConditionB}" Value="False" />
                    </MultiDataTrigger.Conditions>
                    <MultiDataTrigger.Setters>
                        <Setter Property="IsEnabled" Value="False"></Setter>
                    </MultiDataTrigger.Setters>
                </MultiDataTrigger>
            </Style.Triggers>
        </Style>

        ...

    </igWPF:XamDataGrid.Resources>

问候。

答案 1 :(得分:1)

使用CellValuePresenter的样式:

<Style x:Key="DisableForCTE" TargetType="{x:Type iDP:CellValuePresenter}" >
    <Style.Triggers>
        <DataTrigger Binding="{Binding Path=DataItem.CTESubLocation}" Value="No">
              <Setter Property="IsEnabled" Value="False"></Setter>                        
         </DataTrigger>                    
     </Style.Triggers>
</Style>

如果已预定义条件,则可以将cells禁用为列级别:

 <iDP:Field Name="LatestEffectiveDate" Label="Latest Effective Date" >
 <iDP:Field.Settings>
     <iDP:FieldSettings AllowEdit="False">                                       
     </iDP:FieldSettings>
  </iDP:Field.Settings>

答案 2 :(得分:0)

这对我有用:

 dataGrid.EditingSettings.AllowEditing = EditingType.None;