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