zoukankan      html  css  js  c++  java
  • WPF圆角按钮例程

    <Window x:Class="WpfApp3.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
            xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
            xmlns:local="clr-namespace:WpfApp3"
            mc:Ignorable="d"
            Title="我的例程" Height="450" Width="800" Background="Black">
        <Window.Resources>
    
            <Style TargetType="Button" >
                <Setter Property="Template">
                    
                    <Setter.Value>
                        <ControlTemplate TargetType="Button" >
                            <Border x:Name="border" Background="SkyBlue" 
                                    CornerRadius="10" Height="30" BorderBrush="Black" BorderThickness="0" SnapsToDevicePixels="True">
                                <Border.Effect>
                                    <DropShadowEffect Color="Black" Direction="0" ShadowDepth="1" Opacity="1" />
                                </Border.Effect>
                            <TextBlock Text="{TemplateBinding Content}" 
                                      VerticalAlignment="Center" HorizontalAlignment="Center" Foreground="White" FontSize="16" FontFamily="黑体">
                                    <TextBlock.Effect>
                                        <DropShadowEffect Color="Black" Direction="0" ShadowDepth="1" Opacity="1" />
                                    </TextBlock.Effect>
                                </TextBlock>
                            </Border>
                            <ControlTemplate.Triggers>
                                <Trigger Property="IsMouseOver" Value="true">
                                <Setter Property="Background" Value="LightBlue" TargetName="border"></Setter>
                                </Trigger> 
                                <Trigger Property="IsPressed" Value="true">
                                <Setter Property="Background" Value="SkyBlue" TargetName="border"></Setter>
                                </Trigger>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
               
        </Style>
        </Window.Resources>
        <Grid Background="Brown" >
            <Button Content="暂停" HorizontalAlignment="Left" VerticalAlignment="Top" Width="75" Margin="445,344,0,0"></Button>
            <Button Content="添加" HorizontalAlignment="Left" VerticalAlignment="Top" Width="75"  Margin="100,344,0,0"></Button>
            <Button Content="播放" HorizontalAlignment="Left" VerticalAlignment="Top" Width="75" Margin="219,344,0,0"></Button>
            <Button Content="开始" HorizontalAlignment="Left" VerticalAlignment="Top" Width="75" Margin="327,344,0,0" ></Button>
        </Grid>
    </Window>

     这段代码直接使用VS全部粘贴就能够使用。分别演示了圆角,变色,阴影。 需要注意的是因为没有给style输入名字,导致所有的按钮都会被重画。

    每天进步一点点。
  • 相关阅读:
    WIN7 系统 右键计算机 点击管理 出现对话框:找不到文件。
    电脑优化的方法
    小问题总结
    sql server常用函数、常用语句
    java绝对路径和相对路径的理解
    日常开发常用网站(持续更新……)
    jquery字符串序列化方法总结
    J2EE保留小数问题
    error C2556: 'const char &MyString::operator [](int)' : overloaded function differs only by return type from 'char &MyString::operator [](int)'
    有个人愿意对你微笑,如果她的眼神是坚定的,她是谁对我其实已经不重要了
  • 原文地址:https://www.cnblogs.com/snow-zhang/p/9161574.html
Copyright © 2011-2022 走看看