我有一个TextBlock,它有Style={TemplateBinding ParentDependencyProperty}
我需要将一些DataTriggers放在这个TextBlock上,而不是放在整个样式上。
我需要这样的东西:
<TextBlock>
<Style BasedOn="StyleInParentDependencyProperty">
<Style.Triggers>
...
</Style.Triggers>
</Style>
</TextBlock>我不知道怎么做,因为样式的BasedOn属性中不允许绑定。我对WPF非常陌生,而且似乎被困在这里。
谢谢你的帮助。
发布于 2014-01-30 17:01:04
你可以做这样的事
<Style TargetType="TextBlock" x:Key="Default">
<Setter Property="Background" Value="Red"></Setter>
<Setter Property="FontFamily" Value="Segoe Black" />
<Setter Property="HorizontalAlignment" Value="Center" />
<Setter Property="FontSize" Value="32pt" />
<Setter Property="Foreground" Value="#777777" />
</Style>并在需要一些TextBlock的DataTriggers上定义这种样式
<Style BasedOn="{StaticResource Default}" TargetType="TextBlock" x:Key="TextBlockWithTriggers">
<Style.Triggers> .... </Style.Triggers>
</Style>在你的TextBlock上只需定义
<TextBlock Style="{StaticResource TextBlockWithTriggers}"/>https://stackoverflow.com/questions/21461726
复制相似问题