4
我想在數據網格的DataGridCheckBoxColumn中將我的複選框更改爲紅點。所以檢查的項目是紅點,而未檢查的項目是空的。我如何更改DataGridCheckBoxColumn中的樣式?WPF將DataGridCheckBoxColumn更改爲紅點
我想在數據網格的DataGridCheckBoxColumn中將我的複選框更改爲紅點。所以檢查的項目是紅點,而未檢查的項目是空的。我如何更改DataGridCheckBoxColumn中的樣式?WPF將DataGridCheckBoxColumn更改爲紅點
試試這個,它是從stackoverflow.com/questions/1345961/改編而來,它在之前的評論中被Ansel Faillace提及。
<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>
你的問題,對我來說,看起來很像http://stackoverflow.com/questions/1345961/wpf-datagridcheckboxcolumn-custom-style?rq=1這個問題已經發表Anvaka一個公認的答案。 –
作爲一個方面說明,如果您向我們提供有關您已查找過的信息,並嘗試解決您的問題以及發佈一些代碼,我們通常可以更好地爲您提供幫助。 –