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>

二、结果

相关推荐
FPGAI24 分钟前
C++学习之函数
c++·学习
浪子不回头41539 分钟前
推理建模学习笔记
笔记·学习
小张是铁粉40 分钟前
oracle 数据库学习之体系结构(1-4章)
数据库·学习
会编程的吕洞宾41 分钟前
智能体学习记录二之发展史
学习
代码游侠42 分钟前
应用——基于Linux的音乐播放器项目
linux·运维·笔记·学习·算法
myzzb1 小时前
python调用ffmpeg.exe封装装饰类调用
python·学习·ffmpeg·开发
hssfscv1 小时前
Javeweb学习笔记——Vue+Ajax
vue.js·笔记·学习·ajax
专注于大数据技术栈1 小时前
java学习--Math 类常用方法
java·学习
long3162 小时前
类与对象 | 低级别设计 (LLD)
java·spring boot·学习·程序人生·spring·设计模式·学习方法
专注于大数据技术栈2 小时前
java学习--String、StringBuilder、StringBuffer 的核心区别
java·学习