首页 > Windows开发 > 详细

WPF ToggleButton Style

时间:2021-06-17 09:32:31      阅读:25      评论:0      收藏:0      [点我收藏+]
<Style x:Key="ArrowToggleStyle" TargetType="ToggleButton">
    <Setter Property="Background" Value="Gray"/>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="ToggleButton">
                <Border Background="{TemplateBinding Background}">
                    <Grid>
                        <Image x:Name="leftArrowImg" Source="/Graphics/arrow_left24.png" Width="24" Height="24"  HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                        <Image x:Name="rightArrowImg" Source="/Graphics/arrow_right24.png" Width="24" Height="24"  HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                        <ContentPresenter x:Name="content1" Content="not selected" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                        <ContentPresenter x:Name="content2" Content="SELECTED" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                    </Grid>
                </Border>
                <ControlTemplate.Triggers>
                    <Trigger Property="IsChecked" Value="True">
                        <Setter Property="Background" Value="DimGray"/>
                        <Setter TargetName="leftArrowImg" Property="Visibility" Value="Hidden"/>
                        <Setter TargetName="rightArrowImg" Property="Visibility" Value="Visible"/>
                        <Setter TargetName="content1" Property="Visibility" Value="Hidden"/>
                        <Setter TargetName="content2" Property="Visibility" Value="Visible"/>
                    </Trigger>
                    <Trigger Property="IsChecked" Value="False">
                        <Setter TargetName="leftArrowImg" Property="Visibility" Value="Visible"/>
                        <Setter TargetName="rightArrowImg" Property="Visibility" Value="Hidden"/>
                        <Setter TargetName="content1" Property="Visibility" Value="Visible"/>
                        <Setter TargetName="content2" Property="Visibility" Value="Hidden"/>
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

WPF ToggleButton Style

原文:https://www.cnblogs.com/bruce1992/p/14891551.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!