【问题标题】:How to set BackColor of a CheckBox in WPF如何在 WPF 中设置复选框的背景颜色
【发布时间】:2015-03-23 22:26:13
【问题描述】:

在WinForm中我们可以设置CheckBox的BackColor

如何在 WPF 中执行此操作?我试试

<CheckBox Content="CheckBox" Background="Red"/>

但这只会改变矩形边框的颜色

我也试试

<CheckBox>
    <TextBlock Text="CheckBox" Background="Red"/>
</CheckBox>

但这只会改变文本背景颜色,不包括矩形

=======

感谢大家的解决方案。我认为最简单的方法对我有用:)

【问题讨论】:

标签: wpf


【解决方案1】:

如果您对面板进行一些实验,您就会成功:

<Grid Background="Red" HorizontalAlignment="Left">
  <CheckBox Content="test" />
</Grid>

非常接近您想要的。 自己试过了;-)

【讨论】:

    【解决方案2】:
    <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="*" />
                    </Grid.ColumnDefinitions>
                    <CheckBox FlowDirection="RightToLeft" background="Red"
                              IsChecked="False" />
                    <Border Grid.Column="1"
                            Margin="20 0 0 0"
                            HorizontalAlignment="Left"
                            VerticalAlignment="Center"
                            Background="LightGray">
                        <TextBlock HorizontalAlignment="Left"
                                   Foreground="Black"
                                   Style="{StaticResource RegularTextblock}"
                                   Text="Checkbox1" />
                    </Border>
                </Grid>
    

    【讨论】:

      【解决方案3】:

      你要求的太少了。使用 Blend 我为 CheckBox 创建了一个相关的样式。

      代码太大。所以不允许显示。这是馅饼link

      对于Background,有一个网格markGrid。我添加了Background 和TemplateBinding 来强制CheckBox 更改颜色。缺点是如果背景很暗,Path 颜色会很模糊。

      【讨论】:

        猜你喜欢
        • 2012-12-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-12-27
        • 1970-01-01
        • 2016-07-15
        • 2014-10-02
        • 1970-01-01
        相关资源
        最近更新 更多