WPF DataGridCheckBoxColumn自定义样式?

编程入门 行业动态 更新时间:2024-10-23 17:39:26
本文介绍了WPF DataGridCheckBoxColumn自定义样式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 有没有办法在那里设置复选框? iv试图为复选框定义一个样式,但没有起作用。

在使用痣之后,它似乎复选框控件没有ToggleButton,它使用BulleDecorator相反,我不知道这是第一次使用痣..

我想要实现的是,而不是一个复选框,我想要一个红色或绿色的圆圈。

< Style TargetType ={x:Type CheckBox}> < Setter Property =IsHitTestVisibleValue =False/> < Setter Property =FocusableValue =False/> < Setter Property =Horizo​​ntalAlignmentValue =Center/> < Setter Property =VerticalAlignmentValue =Top/> < Setter Property =Template> < Setter.Value> < ControlTemplate TargetType ={x:Type ToggleButton}> < Border x:Name =innerBorder> < Ellipse Fill =#FFFF0000Stroke =#FF000000Stretch =Fillx:Name =statusLightWidth =15Height =15Margin =2VerticalAlignment =Center Horizo​​ntalAlignment =Center/> < / Border> < ControlTemplate.Triggers> < Trigger Property =IsCheckedValue =True> < Setter TargetName =statusLightProperty =FillValue =#FF00FF00/> < / Trigger> < Trigger Property =IsCheckedValue =False> < Setter TargetName =statusLightProperty =FillValue =#FFFF0000/> < / Trigger> < /ControlTemplate.Triggers> < / ControlTemplate> < /Setter.Value> < / Setter> < / Style>

解决方案

看起来你正在寻找DataGridBoundColumn.ElementStyle属性(DataGridCheckBoxColumn派生自DataGridBoundColumn)。如果这对您无效,您可以随时使用DataGridTemplateColumn显示任何您想要的内容。

请参阅 Vincent Sibal的博客,如果你需要更多的信息, / p>

Is there any way to style the checkbox in there? iv tried to define a style for the checkbox but that didn't work.

after using mole it seems like the checkbox control does not have a ToggleButton in it it uses a BulleDecorator instead, im not sure of this first time im using mole..

What i want to achieve is that instead of a check box i want a red or green circle.

<Style TargetType="{x:Type CheckBox}"> <Setter Property="IsHitTestVisible" Value="False"/> <Setter Property="Focusable" Value="False"/> <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 Fill="#FFFF0000" Stroke="#FF000000" Stretch="Fill" x:Name="statusLight" Width="15" Height="15" Margin="2" VerticalAlignment="Center" HorizontalAlignment="Center"/> </Border> <ControlTemplate.Triggers> <Trigger Property="IsChecked" Value="True"> <Setter TargetName="statusLight" Property="Fill" Value="#FF00FF00" /> </Trigger> <Trigger Property="IsChecked" Value="False"> <Setter TargetName="statusLight" Property="Fill" Value="#FFFF0000" /> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style>

解决方案

It looks like you are looking for DataGridBoundColumn.ElementStyle property (DataGridCheckBoxColumn is derived from DataGridBoundColumn). In case this doesn't work for you, you can always use DataGridTemplateColumn to display anything you want.

Refer to Vincent Sibal's blog if you need more information on this.

更多推荐

WPF DataGridCheckBoxColumn自定义样式?

本文发布于:2023-11-08 07:48:06,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1568780.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:自定义   样式   WPF   DataGridCheckBoxColumn

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!