在WPF中,是否可以將「{StaticResource key}」中的鍵綁定到變量。將<object property =「{StaticResource key}」... />中的鍵綁定到值
例如。我有一個變量ExecutionState與狀態有效和已完成。
在我的ResourceDictionary我有
<Style TargetType="{x:Type TextBlock}" x:Key="Active">
<Setter Property="Foreground" Value="Yellow"/>
</Style>
<Style TargetType="{x:Type TextBlock}" x:Key="Completed">
<Setter Property="Foreground" Value="Green"/>
</Style>
而不必
<TextBlock Style="{StaticResource Active}"/>
的我想有一些像
<TextBlock Style="{StaticResource {Binding ExecutionState}}"/>
因此,如果狀態更改文本顏色的變化。 甚至有可能是這樣的嗎? 我可以使用觸發器實現所需的功能,但我必須在幾個地方重複使用它,而且我不想混淆我的代碼。 我也使用MVVM。
thanx