如何在Infragistics XamDataGrid中启用/禁用标题复选框

时间:2018-03-19 14:38:51

标签: wpf mvvm infragistics xamdatagrid

我使用Infragistics XamDataGrid在网格上显示数据。在此网格中,有一个复选框列(列名:" IsSelected")。我在此列的标题中添加了CheckBox以选择全部'选项。

如何根据属性' IsCheckboxHeaderEnabled'启用/禁用此标头CheckBox在ViewModel?

 <igDP:XamDataGrid x:Name="ItemSource" DataSource="{Binding ItemSource,Mode=TwoWay}" Grid.Row="0" Margin="10" AutoFit="true">
    <igDP:XamDataGrid.FieldLayouts>
        <igDP:FieldLayout>
            <igDP:FieldLayout.Fields>
                <igDP:Field Name="IsSelected" Label=" " HorizontalContentAlignment="Left"  Width="Auto" VerticalContentAlignment="Center">
                    <igDP:Field.Settings>
                        <igDP:FieldSettings DataItemUpdateTrigger="OnCellValueChange">
                            <igDP:FieldSettings.LabelPresenterStyle>
                                <Style TargetType="{x:Type igDP:LabelPresenter}">
                                    <Setter Property="ContentTemplate">
                                        <Setter.Value>
                                            <DataTemplate>
                                                <CheckBox Checked="CheckBox_Checked" Unchecked="CheckBox_Unchecked" Content="" IsEnabled="{Binding IsCheckboxHeaderEnabled}"/>
                                            </DataTemplate>
                                        </Setter.Value>
                                    </Setter>
                                </Style>
                            </igDP:FieldSettings.LabelPresenterStyle>
                        </igDP:FieldSettings>
                    </igDP:Field.Settings>
                </igDP:Field>                      
                <igDP:Field Label="Projects" Name="ModelFileName" AllowEdit="False" HorizontalContentAlignment="Left" Width="*"/>
            </igDP:FieldLayout.Fields>
        </igDP:FieldLayout>
    </igDP:XamDataGrid.FieldLayouts>
</igDP:XamDataGrid>

1 个答案:

答案 0 :(得分:2)

只要IsCheckboxHeaderEnabled属性与ItemSource属性在同一个类中定义,这应该可以工作:

<CheckBox ... IsEnabled="{Binding DataContext.IsCheckboxHeaderEnabled, RelativeSource={RelativeSource AncestorType=igDP:XamDataGrid}}"/>