在WPF中的所有Windows中应用按钮样式

前端之家收集整理的这篇文章主要介绍了在WPF中的所有Windows中应用按钮样式前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我的XAML中有一个样式设置,用于在我的WPF窗口中创建圆角按钮。我希望这种风格适用于我应用程序中所有窗口上的所有按钮。

有没有一种方法,类似于CSS,我可以将其放入另一个文件中,并在所有窗口中引用它?或者我只需要每次复制和粘贴。

您可以使用应用程序资源来执行此操作。

这里有一些代码(在app.xaml中)

<Application.Resources>
  <Style TargetType="Button" x:Key="GelButton" >
     <Setter Property="Margin" Value="1,2,1,2"/>
     <Setter Property="HorizontalAlignment" Value="Left"/>
  </Style>
</Application.Resources>

然后,为您的按钮(例如):

<Button Height="50" Width="250" Style="{StaticResource GelButton}" Content="Button 1" />
<Button Height="50" Width="250" Style="{StaticResource GelButton}" Content="Button 2" />

希望这将帮助您找到您要找的东西。

原文链接:https://www.f2er.com/windows/373029.html

猜你在找的Windows相关文章