• 关于一个常用的CheckBox样式


       我们在使用CheckBox的时候,原始的样式有时不能满足我们的需求,这是我们就需要更改其模板,比如我们常用的一种,在播放器中“播放”、“暂停”按钮,其实这也是一种CheckBox,只不过我们只是修改了其相关的模板罢了,下面贴出相关代码: 

    <CheckBox.Style>
      <Style TargetType="{x:Type CheckBox}">
        <Setter Property="Focusable" Value="False" />
        <Setter Property="IsTabStop" Value="False" />
        <!--把OverridesDefaultStyle设置为True,表示这个控件不使用当前Themes的任何属性。-->
        <Setter Property="OverridesDefaultStyle" Value="True" />
          <Style.Triggers>
            <Trigger Property="IsChecked" Value="True">
           <Setter Property="Template">
              <Setter.Value>
                <ControlTemplate TargetType="{x:Type CheckBox}">
                  <Grid Background="Transparent">
                       <Image Source="/EarthSimulation;component/Images/按钮-播放.png"/>
                  </Grid>
                </ControlTemplate>
             </Setter.Value>
          </Setter>
          </Trigger>
          <Trigger Property="IsChecked" Value="False">
           <Setter Property="Template">
             <Setter.Value>
                <ControlTemplate TargetType="{x:Type CheckBox}">
                    <Grid Background="Transparent">
                            <Image Source="/EarthSimulation;component/Images/按钮-暂停.png"/>
                     </Grid>
                </ControlTemplate>
              </Setter.Value>
            </Setter>
            </Trigger>
          </Style.Triggers>
        </Style>
      </CheckBox.Style>
    </CheckBox>  

      

     

  • 相关阅读:
    Java内置包装类
    for循环思路题
    常用函数
    函数
    冒泡排序
    数组的运用
    for循环中有意思的练习题。
    for循环
    运算中容易出现的错误
    分支的运用
  • 原文地址:https://www.cnblogs.com/seekdream/p/4604380.html
Copyright © 2020-2023  润新知