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>

二、结果

相关推荐
STLearner1 小时前
ICML 2026 | LLM×Graph论文总结[2]【Graph4LLM,Graph4Agent,智能体记忆(Memory)
大数据·人工智能·python·深度学习·学习·机器学习·数据挖掘
其实防守也摸鱼2 小时前
KMP全栈开发:从Android到AI Agent的技术演进与实践
android·运维·网络·人工智能·学习·安全·macos
YM52e7 小时前
鸿蒙Flutter Padding内边距:EdgeInsets详解
android·学习·flutter·华为·harmonyos·鸿蒙
西安老张(AIGC&ComfyUI)9 小时前
第034章:ComfyUI&AIGC一阶段学习总结及下阶段学习安排
学习·aigc
正经人_x12 小时前
学习日记43:FINO
学习
网络工程小王14 小时前
【HCIE-AI】11.模型 昇腾迁移适配-精度调试-性能调优
人工智能·学习·华为·迁移学习·昇腾
一只小菜鸡..15 小时前
CMU 15-213 CSAPP:机器级编程与内存的暗黑魔法(Machine-Level)
笔记·学习
吃好睡好便好17 小时前
近期几点体会
学习·生活
xlrqx17 小时前
商丘家电清洗培训零基础学习需掌握哪些要点零基础到底能不能学
python·学习
编程圈子18 小时前
电机驱动开发学习19. 霍尔 BLDC 三段式 FOC 启动算法
驱动开发·学习·算法