【问题标题】:WPF Change DataGridCheckBoxColumn to Red DotsWPF 将 DataGridCheckBoxColumn 更改为红点
【发布时间】:2017-06-07 18:08:58
【问题描述】:

我想在数据网格的 DataGridCheckBoxColumn 中将我的复选框更改为红点。所以选中的项目是红点,而未选中的项目是空的。如何更改 DataGridCheckBoxColumn 中的样式?

【问题讨论】:

  • 在我看来,你的问题很像 stackoverflow.com/questions/1345961/… 这个问题有 Anvaka 发布的公认答案。
  • 附带说明,如果您向我们提供有关您已经查找并尝试解决问题的信息以及发布一些代码,我们通常能够更好地为您提供帮助。跨度>

标签: checkbox styles wpfdatagrid


【解决方案1】:

试试这个,它改编自Ansel Faillace在之前的评论中提到的stackoverflow.com/questions/1345961/

<DataGrid x:Name="dataGrid" Margin="10" ItemsSource="{Binding}">
    <DataGrid.Resources>
        <Style x:Key="GreenRedCheckBox" TargetType="{x:Type Checkbox}">
            <Setter Property="HorizontalAlignment" Value="Center />
            <Setter Property="VerticalAlignment" Value="Top" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type ToggleButton}">
                        <Border x:Name="innerBorder">
                            <Ellipse x:Name="statusLight"
                                     Fill="Red"
                                     Stretch="Fill"
                                     Stroke="Black"
                                     HorizontalAlignment="Center"
                                     VerticalAlignment="Center"
                                     Height="10"
                                     Width="10" />
                        </Border>
                        <Trigger Property="IsChecked" Value="True">
                            <Setter Property="Fill" TargetName="statusLight" Value="Green" />
                        </Trigger>
                        <Trigger Property="IsChecked" Value="False">
                            <Setter Property="Fill" TargetName="statusLight" Value="Red" />
                        </Trigger>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </DataGrid.Resources>
    <DataGrid.Columns>
        <DataGrideCheckBoxColumn ElementStyle="{StaticResource GreenRedCheckBox}"
                                 EditingElementStyle="{StaticResource GreenRedCheckBox}" />
    </DataGrid.Columns>
</DataGrid>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-06-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-27
    • 2010-11-23
    • 2013-10-03
    • 2015-07-28
    相关资源
    最近更新 更多