0
我在创建的style.xaml
ResourceDictionary
文件中有一个按钮样式。如何在XAML的ResourceDictionary文件中调用样式?
我用这个代码来调用它:
<Button Style="{DynamicResource exitButton}" />
但它并没有认识到样式键或者使用静态资源不工作过。如何解决这个问题呢?
我的风格代码:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Style x:Key="exitButton" TargetType="Button">
<Setter Property="Width" Value="22"/>
<Setter Property="Height" Value="32"/>
<Setter Property="Background" Value="#FF7070"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border Width="{TemplateBinding Width}"
Height="{TemplateBinding Height}"
HorizontalAlignment="Center"
VerticalAlignment="Center">
<TextBlock Text="X"
FontSize="15"
Foreground="White"
FontWeight="Bold"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
[WPF参考自定义资源的可能的复制定义在另一个xaml文件](http://stackoverflow.com/questions/15775111/wpf-reference-custom-resource-defined-in-another-xaml-file) –