在 Infragistics XamDataGrid 中将 CheckBoxField 转换为 ToggleButton
Convert CheckBoxField to ToggleButton in Infragistics XamDataGrid
我正在努力将 Infragistics XamDataGrid 中的 CheckBoxField 显示为切换按钮。一切似乎都工作正常,直到我按下那些切换按钮 - 它没有刷新 viewmodel 中的相应值。另一方面,当我更改系统中其他地方的绑定值时,ChecBoxField 会刷新。
如果有人知道如何正确地做,那会让我很高兴。
我的代码:
[...]
<UserControl.Resources>
<ResourceDictionary>
[...]
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type igWpf:CellValuePresenter}">
<ToggleButton Content="{TemplateBinding Value, Converter={StaticResource Converter}}" IsChecked="{TemplateBinding Value}"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
</UserControl.Resources>
[...]
<igWpf:XamDataGrid DataSource="{Binding Oscillators}" AutoFit="true" Grid.Column="1" HorizontalAlignment="Left"
GroupByAreaLocation="None"
IsNestedDataDisplayEnabled="False"
cal:Message.Attach="[Event AssigningFieldLayoutToItem] = [Action AssignFieldLayout($source)] ">
<igWpf:XamDataGrid.FieldLayouts>
<igWpf:FieldLayout>
<igWpf:FieldLayout.Fields>
<igWpf:TextField IsReadOnly="True" Name="Name"></igWpf:TextField>
<igWpf:CheckBoxField Name="OnOff" Label="On/Off">
<igWpf:Field.Settings>
<igWpf:FieldSettings CellValuePresenterStyle="{StaticResource ToggleButtonCellStyle}"></igWpf:FieldSettings>
</igWpf:Field.Settings>
</igWpf:CheckBoxField>
[...]
</igWpf:NumericField>
</igWpf:FieldLayout.Fields>
</igWpf:FieldLayout>
</igWpf:XamDataGrid.FieldLayouts>
[...]
</igWpf:XamDataGrid>
好的,我知道了。这是正确的绑定,双向工作:
<Setter.Value>
<ControlTemplate TargetType="{x:Type igWpf:CellValuePresenter}">
<ToggleButton Content="{TemplateBinding Value, Converter={StaticResource Converter}}" IsChecked="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Value}"/>
</ControlTemplate>
</Setter.Value>
我正在努力将 Infragistics XamDataGrid 中的 CheckBoxField 显示为切换按钮。一切似乎都工作正常,直到我按下那些切换按钮 - 它没有刷新 viewmodel 中的相应值。另一方面,当我更改系统中其他地方的绑定值时,ChecBoxField 会刷新。 如果有人知道如何正确地做,那会让我很高兴。
我的代码:
[...]
<UserControl.Resources>
<ResourceDictionary>
[...]
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type igWpf:CellValuePresenter}">
<ToggleButton Content="{TemplateBinding Value, Converter={StaticResource Converter}}" IsChecked="{TemplateBinding Value}"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
</UserControl.Resources>
[...]
<igWpf:XamDataGrid DataSource="{Binding Oscillators}" AutoFit="true" Grid.Column="1" HorizontalAlignment="Left"
GroupByAreaLocation="None"
IsNestedDataDisplayEnabled="False"
cal:Message.Attach="[Event AssigningFieldLayoutToItem] = [Action AssignFieldLayout($source)] ">
<igWpf:XamDataGrid.FieldLayouts>
<igWpf:FieldLayout>
<igWpf:FieldLayout.Fields>
<igWpf:TextField IsReadOnly="True" Name="Name"></igWpf:TextField>
<igWpf:CheckBoxField Name="OnOff" Label="On/Off">
<igWpf:Field.Settings>
<igWpf:FieldSettings CellValuePresenterStyle="{StaticResource ToggleButtonCellStyle}"></igWpf:FieldSettings>
</igWpf:Field.Settings>
</igWpf:CheckBoxField>
[...]
</igWpf:NumericField>
</igWpf:FieldLayout.Fields>
</igWpf:FieldLayout>
</igWpf:XamDataGrid.FieldLayouts>
[...]
</igWpf:XamDataGrid>
好的,我知道了。这是正确的绑定,双向工作:
<Setter.Value>
<ControlTemplate TargetType="{x:Type igWpf:CellValuePresenter}">
<ToggleButton Content="{TemplateBinding Value, Converter={StaticResource Converter}}" IsChecked="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Value}"/>
</ControlTemplate>
</Setter.Value>