WPF DataGridCheckBoxColumn自定义样式? [英] WPF DataGridCheckBoxColumn custom style?

查看:301
本文介绍了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自定义样式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆