スタイル内にResourceDictionaryを定義することはできますか?リソースまたはResourceDictionaryをスタイルに追加できますか?
たとえば、StackPanelsに2つの異なるスタイルを設定し、すべてのボタンを青色にし、もう一方を赤色にしたいとします。これは可能ですか?上記のコードは、セッターのプロパティ値についてのエラーで失敗し
<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>
よう
何かが(それは明らかにnullではないにもかかわらず)nullにすることはできません。
スタイルへのResourceDictionaryをマージする方法があった場合、私は思っていたしかし、私は
<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} />
ような何かを行うことができます。
おかげで、私はあなたがおそらく正しいと思います。 ResourcesプロパティでDynamicResourceを使用することはできません。 – Rachel