是否可以在樣式中定義ResourceDictionary?我可以將資源或ResourceDictionary添加到樣式嗎?
例如,假設我想爲StackPanels提供兩種不同的樣式,並且我希望所有按鈕都是藍色,而另一個我希望它們是紅色。這可能嗎?
喜歡的東西
<Style x:Key="RedButtonsPanel" TargetType="{x:Type StackPanel}">
<Setter Property="Orientation" Value="Horizontal" />
<Setter Property="StackPanel.Resources">
<Setter.Value>
<ResourceDictionary>
<Style TargetType="{x:Type Button}">
<Setter Property="Background" Value="Red" />
</Style>
</ResourceDictionary>
</Setter.Value>
</Setter>
</Style>
上面的代碼失敗有關二傳手的屬性值的誤差不能爲空(即使這顯然不爲空)。
我可以這樣做
<ResourceDictionary x:Key="RedButtons">
<Style TargetType="{x:Type Button}">
<Setter Property="Width" Value="100" />
<Setter Property="Background" Value="Red" />
</Style>
</ResourceDictionary>
<StackPanel Resources={StaticResource RedButtons} />
但是我不知道是否有辦法在ResourceDictionary中融入風格。
謝謝你,我想你大概是對的。我無法將ResourceResource與Resources屬性一起使用。 – Rachel 2010-11-23 14:46:48