代码之家  ›  专栏  ›  技术社区  ›  walterhuang

如何在WPF中设置CheckBox的BackColor

wpf
  •  5
  • walterhuang  · 技术社区  · 11 年前

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

    enter image description here

    如何在WPF中执行此操作?我尽力了

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

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

    enter image description here

    我也尝试过

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

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

    enter image description here

    =======

    感谢大家的解决方案。我认为最简单的方法适合我:)

    3 回复  |  直到 11 年前
        1
  •  10
  •   Philip Stuyck    11 年前

    如果你在面板上做一点实验,你就可以做到:

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

    非常接近你想要的。 自己尝试过;-)

        2
  •  4
  •   Jayasri    11 年前
    <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
  •  1
  •   Sandesh    11 年前

    你要求太多了。使用我制作的Blend为 CheckBox .

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

    对于 Background 有一个网格 markGrid 。我添加了 出身背景 和一个 TemplateBinding 强制 复选框 改变颜色。缺点是如果背景较暗,路径颜色将非常微弱地可见。

    enter image description here