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>

二、结果

相关推荐
楼田莉子17 小时前
C++动态规划算法:斐波那契数列模型
c++·学习·算法·动态规划
江流月照17 小时前
IP验证学习之agent编写
学习·硬件架构·硬件工程
DisonTangor18 小时前
【阿里拥抱开源】Qwen团队开源新一代深度思考模型——Qwen3-Next-80B-A3B-Thinking
人工智能·学习·语言模型·开源·aigc
军训猫猫头19 小时前
12.NModbus4在C#上的部署与使用 C#例子 WPF例子
开发语言·c#·wpf
我要打打代码19 小时前
在WPF项目中使用阿里图标库iconfont
wpf
MuMuMu#19 小时前
Spring Cloud Gateway基础复习
java·运维·学习
尚久龙21 小时前
安卓学习 之 SeekBar(音视频播放进度条)
android·java·学习·手机·android studio
人生游戏牛马NPC1号1 天前
学习 Android (二十二) 学习 OpenCV (七)
android·opencv·学习
FlYFlOWERANDLEAF1 天前
DevExpress中Word Processing Document API学习记录
学习·c#·word
半夏知半秋1 天前
基于跳跃表的zset实现解析(lua版)
服务器·开发语言·redis·学习·lua