WPF学习(2) -- 样式基础

一、代码

<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>

二、结果

相关推荐

  1. WPF 基础入门(样式

    2024-07-13 12:38:04       57 阅读
  2. wpf 按钮禁用样式

    2024-07-13 12:38:04       30 阅读
  3. WPF设置全局样式

    2024-07-13 12:38:04       26 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-13 12:38:04       67 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-13 12:38:04       72 阅读
  3. 在Django里面运行非项目文件

    2024-07-13 12:38:04       58 阅读
  4. Python语言-面向对象

    2024-07-13 12:38:04       69 阅读

热门阅读

  1. AI技术应用的利弊

    2024-07-13 12:38:04       26 阅读
  2. spring boot easyexcel

    2024-07-13 12:38:04       23 阅读
  3. Curator分布式锁

    2024-07-13 12:38:04       24 阅读
  4. 面试真题 | ARM体系架构基础知识

    2024-07-13 12:38:04       27 阅读
  5. 国内Ubuntu安装 stable-diffusion教程,换成国内镜像

    2024-07-13 12:38:04       22 阅读
  6. 【微服务】Spring Cloud中如何使用Eureka

    2024-07-13 12:38:04       20 阅读
  7. 视觉定位是否比GPS更精确?

    2024-07-13 12:38:04       20 阅读
  8. string的模拟实现

    2024-07-13 12:38:04       15 阅读
  9. 源码编译安装LAMP

    2024-07-13 12:38:04       22 阅读