欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 财经 > 金融 > WPF学习(2) -- 样式基础

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

2024/10/24 9:31:08 来源:https://blog.csdn.net/Fourglsl/article/details/140396949  浏览:    关键词: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>

二、结果

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com