我有一系列TextBlocks,我想为它们应用样式和DataTrigger。唯一的区别是每个TextBlock绑定到视图模型中的不同属性。
下面是一个简化版本的TextBlock,其中包含“内置”的样式和DataTrigger。
<TextBlock Text="Is development">
<TextBlock.Style>
<Style TargetType="{x:Type TextBlock}">
<Style.Triggers>
<DataTrigger Binding="{Binding IsDevelopmentIsDirty}"
Value="True">
<Setter Property="FontWeight"
Value="Bold" />
<Setter Property="FontStyle"
Value="Italic" />
<Setter Property="Foreground"
Value="{StaticResource SCB_TardisBlue}" />
</DataTrigger>
</Style.Triggers>
</Style>
</TextBlock.Style>
</TextBlock>
因此,在前面的示例中,“IsDevelopmentIsDirty”绑定对于每个TextBlock都是不同的。
我并没有找到将此样式合并为一个声明以供整个TextBlocks系列使用的最佳方法,运气不是很好。
是否有一种方法可以分配样式和DataTrigger应绑定的属性?如果没有,有什么方法可以做到这一点?提前致谢。