zoukankan      html  css  js  c++  java
  • WPF两个按钮来回切换样式

     <!-- 两个按钮来回切换样式 -->
        <Style x:Key="SwicthFunctionMetroToggleButton" TargetType="{x:Type ToggleButton}">
            <Setter Property="Background" Value="White" />
            <Setter Property="BorderBrush" Value="Black" />
            <Setter Property="BorderThickness" Value="1" />
            <Setter Property="MetroControls:ControlsHelper.CornerRadius" Value="0" />
            <Setter Property="FontFamily" Value="Meiryo" />
            <Setter Property="FontSize" Value="15" />
            <Setter Property="FontWeight" Value="Bold" />
            <Setter Property="Foreground" Value="Black" />       
            <Setter Property="SnapsToDevicePixels" Value="True" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="ToggleButton">
                        <Grid>
                            <Border x:Name="_Border"
                                    Background="{TemplateBinding Background}"
                                    BorderBrush="{TemplateBinding BorderBrush}"
                                    BorderThickness="{TemplateBinding BorderThickness}"
                                    CornerRadius="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(MetroControls:ControlsHelper.CornerRadius), Mode=OneWay}"
                                    SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
                            <Border x:Name="DisabledVisualElement"
                                    Background="{DynamicResource ControlsDisabledBrush}"
                                    CornerRadius="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(MetroControls:ControlsHelper.CornerRadius), Mode=OneWay}"
                                    IsHitTestVisible="False"
                                    Opacity="0"
                                    SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
                            <MetroControls:ContentControlEx x:Name="PART_ContentPresenter"
                                                       Margin="{TemplateBinding BorderThickness}"
                                                       Padding="{TemplateBinding Padding}"
                                                       HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
                                                       VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
                                                       Content="{TemplateBinding Content}"
                                                       ContentCharacterCasing="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(MetroControls:ControlsHelper.ContentCharacterCasing)}"
                                                       ContentStringFormat="{TemplateBinding ContentStringFormat}"
                                                       ContentTemplate="{TemplateBinding ContentTemplate}"
                                                       ContentTemplateSelector="{TemplateBinding ContentTemplateSelector}"
                                                       RecognizesAccessKey="True"
                                                       SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
                        </Grid>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsChecked" Value="True">
                                <Setter TargetName="_Border" Property="Background" Value="#4e81bd" />
                                <Setter Property="Foreground" Value="White" />
                            </Trigger>
                            <Trigger Property="IsChecked" Value="False">
                                <Setter TargetName="_Border" Property="Background" Value="White" />
                                <Setter Property="Foreground" Value="Black" />
                            </Trigger>
                            <!--<Trigger Property="IsKeyboardFocusWithin" Value="True">
                                <Setter TargetName="_Border" Property="Background" Value="#4e81bd" />
                                <Setter Property="Foreground" Value="White" />
                            </Trigger>-->
                            <!--<Trigger Property="IsEnabled" Value="False">
                                <Setter TargetName="DisabledVisualElement" Property="Opacity" Value="0.7" />
                                <Setter TargetName="PART_ContentPresenter" Property="Opacity" Value="0.3" />
                            </Trigger>-->
                            <Trigger Property="IsMouseOver" Value="True">
                                <Setter TargetName="_Border" Property="Background" Value="#e6e6e6"/>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
            <!--<Style.Triggers>
                <Trigger Property="IsChecked" Value="True">
                    <Setter Property="Background" Value="{DynamicResource GrayBrush2}" />
                    <Setter Property="BorderBrush" Value="{DynamicResource GrayBrush5}" />
                </Trigger>
                <MultiTrigger>
                    <MultiTrigger.Conditions>
                        <Condition Property="IsMouseOver" Value="True" />
                        <Condition Property="IsChecked" Value="False" />
                    </MultiTrigger.Conditions>
                    <Setter Property="Background" Value="{DynamicResource GrayBrush8}" />
                </MultiTrigger>
                <MultiTrigger>
                    <MultiTrigger.Conditions>
                        <Condition Property="IsMouseOver" Value="True" />
                        <Condition Property="IsChecked" Value="True" />
                    </MultiTrigger.Conditions>
                    <Setter Property="Background" Value="{DynamicResource GrayBrush3}" />
                </MultiTrigger>
                <Trigger Property="IsPressed" Value="True">
                    <Setter Property="Background" Value="{DynamicResource GrayBrush7}" />
                </Trigger>
                <Trigger Property="IsKeyboardFocusWithin" Value="True">
                    <Setter Property="BorderBrush" Value="{DynamicResource ButtonMouseOverBorderBrush}" />
                </Trigger>
            </Style.Triggers>-->
        </Style>
    View Code

    使用如下

     <ToggleButton x:Name="uiuserdataImpTbtnContent" Style="{StaticResource SwicthFunctionMetroToggleButton}"
                                      Width="80" Height="25" Content="{x:Static const:Resources.TextImportResultLabContent}" Margin="0,1,1,0" FontSize="11"
                                      IsChecked="{Binding TBContentIsChecked}"
                                      IsEnabled="{Binding TBTagIsChecked}"
                                      Visibility="{Binding IsContentVisibility}"
                                />
                        <ToggleButton x:Name="uiuserdataImpTbtnTag" Style="{StaticResource SwicthFunctionMetroToggleButton}"
                                      Width="80" Height="25" Content="{x:Static const:Resources.TextImportResultLabTag}" Margin="-2,1,1,0" FontSize="11"
                                      IsChecked="{Binding TBTagIsChecked}"
                                      IsEnabled="{Binding TBContentIsChecked}" VerticalAlignment="Top"
                                      Visibility="{Binding IsTagVisibility}"
                                      />
    View Code
  • 相关阅读:
    微信小程序支付【前端】
    CSS主题切换
    利用Proxy写了个存储管理
    前端存储cookie操作
    canvas电子签名和播放划线
    【原创】[Ext.ux.UploadDialog] 控件使用说明及在Ext 3.x下问题解决
    【原创】分享一组VC++底层图像处理函数
    【转发】SQL Server数据库被质疑解决方案
    SVN 解决update失败出现乱码提示或工作副本已经锁定
    Qt 外部子模块的3种使用方法,以QtXlsx为例
  • 原文地址:https://www.cnblogs.com/ilison/p/10893674.html
Copyright © 2011-2022 走看看