WPF学习(2) -- 样式基础

一、代码

XML 复制代码
<Window x:Class="学习.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:学习"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">

    <Window.Resources>
        <Style x:Key="BaseButtonStytle" TargetType="Button"><!--创建一个按键的公用基础样式-->
            <Setter Property="FontSize" Value="20"/><!--字体大小-->
            <Setter Property="Foreground" Value="Black"/><!--字体颜色-->
            <Style.Triggers>
                <Trigger Property="IsMouseOver" Value="True">
                    <Setter Property="Background" Value="LightBlue"/> <!--鼠标悬浮会变蓝色-->
                </Trigger>
            </Style.Triggers>
        </Style>

        <Style x:Key="ButtonStytle" TargetType="Button" BasedOn="{StaticResource BaseButtonStytle}"><!--继承共用基础样式的按键样式-->
            <Setter Property="Background" Value="Green"/><!--按键背景为绿色-->
        </Style>
    </Window.Resources>
    <Grid>
        <StackPanel>
            <Button Content="111" Style="{StaticResource ButtonStytle}" />
            <Button Content="111" Style="{StaticResource ButtonStytle}" />
            <Button Content="111" Style="{StaticResource ButtonStytle}" />
        </StackPanel>
    </Grid>
</Window>

二、结果

相关推荐
小朝说技术2 分钟前
Golang学习总结
开发语言·后端·学习·golang
honey ball21 分钟前
Cadence高速板设计技巧(全志H3)[三]
网络·单片机·嵌入式硬件·学习
界面开发小八哥1 小时前
「对比评测」标准WPF DataGrid与DevExpress WPF GridControl有何不同?(二)
.net·wpf·界面控件·devexpress·ui开发
TIF星空1 小时前
【 WPF 中常用的Brush类的简要介绍、使用方法和适用场景】
经验分享·c#·wpf
Ares-Wang1 小时前
WPF ToolkitMVVM IOC IServiceConllection
wpf
koka_jerry1 小时前
嵌入式学习——ARM学习(1)
arm开发·学习
Sundayday472 小时前
ssh---配置密钥对验证
linux·运维·服务器·学习·云计算·ssh
zhoukeguai2 小时前
postman学习笔记:从入门到精通
笔记·学习·postman
skywalk81632 小时前
学习关系型数据库:在MAC下编译安装firebird
数据库·学习·macos
小陈从不熬夜3 小时前
Ajax学习笔记
javascript·笔记·学习·ajax·html5