【发布时间】:2014-12-11 14:17:42
【问题描述】:
以下控件定义可以正常工作:
<local:TextBoxEx Text="{Binding Title, UpdateSourceTrigger=PropertyChanged, Delay=900}"
Foreground="{Binding Selection.Error, Converter={StaticResource BoolToErrorBrush}}"/>
当我使用样式更改它时:
<Style x:Key="TextBoxTitle" TargetType="local:TextBoxEx">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<local:TextBoxEx Text="{Binding Text, RelativeSource={RelativeSource TemplatedParent}, UpdateSourceTrigger=PropertyChanged}"
Foreground="Blue"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<local:TextBoxEx Text="{Binding Title, UpdateSourceTrigger=PropertyChanged, Delay=900}"
Style="{StaticResource TextBoxTitle}"
Foreground="Pink"/>
与 Title 的绑定会否决与 Text 的样式绑定并起作用。
设置前景色没有效果,它仍然是蓝色。
当我在 controltemplate 样式中使用Foreground="{TemplateBinding Foreground}" 时,它可以工作。
我无法理解这种行为,你能理解吗?
在第一种情况下,本地定义领先,在第二种情况下不是。
【问题讨论】:
标签: wpf xaml properties operator-precedence