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>

二、结果

相关推荐
列星随旋10 小时前
redis分片集群的部署和使用
redis·学习
Chennnng10 小时前
rsl_rl框架学习
学习
xixixi7777711 小时前
剖析Agent(代理)攻击面
网络·学习·安全·架构·网络攻击模型·代理
Jerry.张蒙11 小时前
SAP传输请求流程:从开发到生产的安全流转
大数据·网络·人工智能·学习·职场和发展·区块链·运维开发
Century_Dragon11 小时前
VR+智能评——比亚迪秦EV整车检测与诊断仿真实训系统
学习
victory043111 小时前
大模型后训练学习计划 02 verl llamafactory
学习
tfjy199712 小时前
网络基础学习
网络·学习
Miketutu12 小时前
操作系统中进程与作业的概念区分
学习
TL滕12 小时前
从0开始学算法——第三天(数据结构的操作)
数据结构·笔记·学习·算法
九千七52612 小时前
sklearn学习(4)K近邻(KNN)
人工智能·学习·机器学习·sklearn·knn·近邻搜索