记录一些WPF常用样式方便以后复用(二)(Button、CheckBox、输入账号密码框)...

Button (一)

imageimage

<Style x:Key="ButtonSaveStyle" TargetType="{x:Type Button}">
            <Setter Property="FocusVisualStyle" Value="{StaticResource ButtonFocusVisual}"/>
            <Setter Property="Background" Value="{StaticResource ButtonNormalBackground}"/>
            <Setter Property="BorderBrush" Value="{StaticResource ButtonNormalBorder}"/>
            <Setter Property="BorderThickness" Value="1"/>
            <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
            <Setter Property="HorizontalContentAlignment" Value="Center"/>
            <Setter Property="VerticalContentAlignment" Value="Center"/>
            <Setter Property="Padding" Value="1"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type Button}">
                        <Border  x:Name="Chrome" CornerRadius="5" Background="{Binding Background, RelativeSource={RelativeSource TemplatedParent}}" >
                            <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                        </Border>
                        <!--<Themes:ButtonChrome x:Name="Chrome" BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}" RenderMouseOver="{TemplateBinding IsMouseOver}" RenderPressed="{TemplateBinding IsPressed}" RenderDefaulted="{TemplateBinding IsDefaulted}" SnapsToDevicePixels="true">
                            <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                        </Themes:ButtonChrome>-->
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsMouseOver" Value="True">
                                <Setter Property="Background" TargetName="Chrome" Value="{Binding BorderBrush, RelativeSource={RelativeSource TemplatedParent}}"/>
                            </Trigger>
                            <Trigger Property="IsEnabled" Value="false">
                                <Setter Property="Foreground" Value="#ADADAD"/>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
<!--Background为背景颜色,BorderBrush为鼠标移入的背景-->
     <Button Width="100" Height="35" VerticalAlignment="Top" Background="#FFFD5F4F" BorderBrush="#FFEC685C" Content="保存" Style="{DynamicResource ButtonSaveStyle}" Foreground="White" TextOptions.TextFormattingMode="Display" FontSize="13.333"/>

Button(二)

image

<Style x:Key="ButtonStyle1" TargetType="{x:Type Button}">
            <Setter Property="FocusVisualStyle" Value="{StaticResource ButtonFocusVisual}"/>
            <Setter Property="Background" Value="{StaticResource ButtonNormalBackground}"/>
            <Setter Property="BorderBrush" Value="{StaticResource ButtonNormalBorder}"/>
            <Setter Property="BorderThickness" Value="1"/>
            <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
            <Setter Property="HorizontalContentAlignment" Value="Center"/>
            <Setter Property="VerticalContentAlignment" Value="Center"/>
            <Setter Property="Padding" Value="1"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type Button}">
                        <Border x:Name="border" Width="36" Height="36"  Background="#FF373737" CornerRadius="18" BorderBrush="White" BorderThickness="1" SnapsToDevicePixels="True">
                            <Path Data="M11,11 L24,24 M24,11 L11,24" Fill="White" x:Name="path" HorizontalAlignment="Center" Height="14"  Stretch="Fill" Stroke="White" VerticalAlignment="Center" Width="14"/>
                        </Border>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsMouseOver" Value="True" SourceName="border">
                                <Setter Property="Background" TargetName="border" Value="#FFB90F0F"/>
                                <Setter Property="BorderBrush" TargetName="border" Value="White"/>
                            </Trigger>
                        </ControlTemplate.Triggers>
                        <!--<Themes:ButtonChrome x:Name="Chrome" BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}" RenderMouseOver="{TemplateBinding IsMouseOver}" RenderPressed="{TemplateBinding IsPressed}" RenderDefaulted="{TemplateBinding IsDefaulted}" SnapsToDevicePixels="true">
                            <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                        </Themes:ButtonChrome>-->

                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

Checkbox样式

imageimage

 

<Style x:Key="CheckBoxStyle1" TargetType="{x:Type CheckBox}">
   <Setter Property="OverridesDefaultStyle" Value="True"/>
        <Setter Property="SnapsToDevicePixels" Value="True"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type CheckBox}">
                    <BulletDecorator FlowDirection="LeftToRight" VerticalAlignment="Center">
                        <BulletDecorator.Bullet>
                            <Border x:Name="bd"  
                                    BorderThickness="1"  
                                    BorderBrush="#B2B2B2"  
                                    MinHeight="13"  
                                    MinWidth="13"  
                                    VerticalAlignment="Center" Background="White">
                                <Path x:Name="cp" Width="12" Height="12"  
                                      Stroke="#4892E7"  
                                      StrokeThickness="2"/>
                            </Border>

                        </BulletDecorator.Bullet>
                        <TextBlock x:Name="textBlock" Margin="2,0" Text="{Binding Content, RelativeSource={RelativeSource TemplatedParent}}" FontFamily="Microsoft YaHei UI" FontSize="13.333"></TextBlock>
                    </BulletDecorator>
                    <!-- 
                        控件触发器 
                    -->
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsChecked" Value="True">
                            <!-- 画上一个勾 -->
                            <Setter TargetName="cp" Property="Data"  
                                    Value="M 2,6 L 5,9 11,2"/>
                            <Setter Property="Foreground" TargetName="textBlock" Value="#FFE60E0E"/>

                        </Trigger>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter TargetName="bd" Property="BorderBrush" Value="#1583DD">
                            </Setter>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
</Style>


 <CheckBox Content="记住密码" Panel.ZIndex="1" Width="80" Height="20"  Grid.Row="7" Grid.Column="0"  x:Name="IsRememberUserMMBox" Grid.ColumnSpan="2" HorizontalAlignment="Left" Margin="55,0,0,0" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" Style="{DynamicResource CheckBoxStyle1}" Foreground="Gray" />

 

 

输入账号和密码提示框

<TextBox Grid.Row="3" Grid.Column="1" Margin="5,4,0,6" BorderBrush="Transparent" BorderThickness="0" VerticalContentAlignment="Center" Text=""  FontSize="16">
                        <TextBox.Style>
                            <Style TargetType="TextBox">
                                <Style.Triggers>
                                    <Trigger Property="Text" Value="{x:Null}">
                                        <Setter Property="Background" >
                                            <Setter.Value>
                                                <VisualBrush Stretch="None">
                                                    <VisualBrush.Visual>
                                                        <TextBox BorderThickness="0" BorderBrush="Transparent"   VerticalContentAlignment="Center" Width="310"  Background="#0000" FontSize="13"  HorizontalAlignment="Left" Foreground="Gray" Text="请输入用户名"/>
                                                    </VisualBrush.Visual>
                                                </VisualBrush>
                                            </Setter.Value>
                                        </Setter>
                                    </Trigger>
                                    <Trigger Property="Text" Value="">
                                        <Setter Property="Background" >
                                            <Setter.Value>
                                                <VisualBrush Stretch="None">
                                                    <VisualBrush.Visual>
                                                        <TextBox BorderThickness="0" BorderBrush="Transparent"   VerticalContentAlignment="Center" Width="310"  Background="#0000" FontSize="13"  HorizontalAlignment="Left" Foreground="Gray" Text="请输入用户名"/>
                                                    </VisualBrush.Visual>
                                                </VisualBrush>
                                            </Setter.Value>
                                        </Setter>
                                    </Trigger>
                                </Style.Triggers>
                            </Style>
                        </TextBox.Style>

                    </TextBox>
                    <PasswordBox Grid.Row="5" Grid.Column="1" x:Name="pbUserPassWord" BorderBrush="Transparent" BorderThickness="0" Margin="5,4,0,6" Password="" VerticalContentAlignment="Center" FontSize="16" PasswordChanged="pbUserPassWord_PasswordChanged">
                        <PasswordBox.Style>
                            <Style TargetType="PasswordBox">
                                <Style.Triggers>
                                    <Trigger Property="Tag" Value="{x:Null}">
                                        <Setter Property="Background" >
                                            <Setter.Value>
                                                <VisualBrush Stretch="None">
                                                    <VisualBrush.Visual>
                                                        <TextBox BorderThickness="0" BorderBrush="Transparent"   VerticalContentAlignment="Center" Width="310"  Background="#0000" FontSize="13"  HorizontalAlignment="Left" Foreground="Gray" Text="请输入密码"/>
                                                    </VisualBrush.Visual>
                                                </VisualBrush>
                                            </Setter.Value>
                                        </Setter>
                                    </Trigger>
                                    <Trigger Property="Tag" Value="">
                                        <Setter Property="Background" >
                                            <Setter.Value>
                                                <VisualBrush Stretch="None">
                                                    <VisualBrush.Visual>
                                                        <TextBox BorderThickness="0" BorderBrush="Transparent"   VerticalContentAlignment="Center" Width="310"  Background="#0000" FontSize="13"  HorizontalAlignment="Left" Foreground="Gray" Text="请输入密码"/>
                                                    </VisualBrush.Visual>
                                                </VisualBrush>
                                            </Setter.Value>
                                        </Setter>
                                    </Trigger>
                                </Style.Triggers>
                            </Style>
                        </PasswordBox.Style>

                    </PasswordBox>

转载于:https://www.cnblogs.com/A-sync/p/5764278.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值