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>

二、结果

相关推荐
博览鸿蒙6 小时前
FPGA 开发软件学习笔记分享(内含安装与环境配置)
笔记·学习·fpga开发
反向跟单策略7 小时前
期货反向跟单-贵金属牛市中的反向跟单密码
大数据·人工智能·学习·数据分析·区块链
kingmax542120087 小时前
NOAI和IOAI竞赛学习路径
人工智能·学习·青少年编程
其美杰布-富贵-李7 小时前
pycalphad 学习笔记
笔记·学习·热力学计算
木木木一7 小时前
Rust学习记录--C10 泛型,Trait,生命周期
python·学习·rust
Moonquakes5408 小时前
嵌入式基础学习笔记(51)
笔记·单片机·学习
musenh8 小时前
spring学习1
java·学习·spring
Engineer邓祥浩8 小时前
设计模式学习(12) 23-10 外观模式
学习·设计模式·外观模式
专注于大数据技术栈8 小时前
java学习--Vector
java·学习
_叶小格_8 小时前
ansible自动化入门基础
运维·笔记·学习·自动化·ansible