WPF 重写 setter 属性
我在 XAML 中使用样式作为标签:
<Style x:Key="TreatEye" TargetType="Label">
<Setter Property="Foreground" Value="#d1d1d1" />
<Setter Property="FontWeight" Value="Bold" />
<Setter Property="FontSize" Value="30" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Label">
<Canvas>
<TextBlock x:Name="retreatText" Canvas.Left="80" Canvas.Top="5" FontSize="16" Text="Retreatment"/>
<TextBlock x:Name="bioinsulatorText" Canvas.Left="21" Canvas.Top="33" Text="Bioinsulator" />
<TextBlock x:Name="kxlText" Canvas.Left="21" Canvas.Top="70" Text="KXL Kit" />
</Canvas>
...
我看到的问题是“reatreatText”的 FontSize 属性未从 setter 值 30 覆盖。这构建得很好,但最终显示有“reatreatText”大小为 30。为什么这个值没有被覆盖?
提前致谢。
I'm using a style in my XAML for a label:
<Style x:Key="TreatEye" TargetType="Label">
<Setter Property="Foreground" Value="#d1d1d1" />
<Setter Property="FontWeight" Value="Bold" />
<Setter Property="FontSize" Value="30" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Label">
<Canvas>
<TextBlock x:Name="retreatText" Canvas.Left="80" Canvas.Top="5" FontSize="16" Text="Retreatment"/>
<TextBlock x:Name="bioinsulatorText" Canvas.Left="21" Canvas.Top="33" Text="Bioinsulator" />
<TextBlock x:Name="kxlText" Canvas.Left="21" Canvas.Top="70" Text="KXL Kit" />
</Canvas>
...
The problem I'm seeing is that the FontSize property of "reatreatText" is not overridden from the setter value of 30. This builds fine, but the end display has "reatreatText" as size 30. Why is this value not overridden?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
抱歉,但我在 Kaxaml 中尝试了您的代码并按预期工作:
结果:
alt text http: //img231.imageshack.us/img231/695/capture2p.png
Sorry, but I tried your code inside Kaxaml and works as expected:
Result:
alt text http://img231.imageshack.us/img231/695/capture2p.png
您需要在 TextBlock 上设置 TemplateBinding。
这就是 setter 属性传播到内部结构的方式。
You need to set a TemplateBinding on the TextBlock.
That's how the setter properties get propogated to the internal structure.