2012-04-21 129 views
1

有什麼辦法如何設置WPF樣式的圖像大小?通過WPF樣式設置圖像的寬度和高度

我有我的XAML: <Image Style="MyImageStyle" Source="{StaticResource MyImage}" />

而且在ResourceDictionary中作爲一種風格:

<Style x:Key="MyImageStyle"> 
<Setter Property="Width" Value="30" /> 

但doesn't工作。我得到這個錯誤:無法解析樣式屬性'寬度'。驗證擁有的類型是Style的TargetType,還是使用Class.Property語法指定屬性。

Thx。

+0

可能需要閱讀更多有關[風格](http://msdn.microsoft.com/en-us/library/ms745683.aspx).. 。 – 2012-04-21 15:58:49

回答

2
<Style x:Key="myImageStyle" TargetType="{x:Type Image}"> 
    <Setter Property="Width" Value="30" /> 
... 

<Image Style="{StaticResource MyImageStyle}" Source="{StaticResource MyImage}" /> 
相關問題