在所有的Windows在WPF应用样式按钮 [英] Apply style for buttons in all Windows in WPF
问题描述
我在我的XAML的样式设置为我的WPF窗口创建圆角按钮
取值。我想这种风格应用到所有按钮上的所有窗口在我的申请。
I have a style setup in my XAML for the creation of round corner Button
s in my WPF window. I would like this style to apply to all buttons on all windows in my application.
有没有一种方法,类似于CSS,我可以把这个到另一个文件中,在我的所有窗口以某种方式引用它?或者,我只是需要复制和每次粘贴。
Is there a way, similar to CSS, that I could put this into another file and reference it somehow in all my windows? Or do I just need to copy and paste it every time.
推荐答案
您可以使用该应用程序的资源来做到这一点。
You could use the application resources to do that.
下面是一个有点code的例如(在App.xaml中)
Here's a bit of code for example (in 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>
和然后,为您的按钮(例如):
and then, for your buttons (for example):
<Button Height="50" Width="250" Style="{StaticResource GelButton}" Content="Button 1" />
<Button Height="50" Width="250" Style="{StaticResource GelButton}" Content="Button 2" />
希望这将帮助你找到你要找的东西。
Hope this will help you to find what you're looking for.
这篇关于在所有的Windows在WPF应用样式按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!