<TextBlock Text="{Binding MyTextProperty}">
<TextBlock.Style>
<Style TargetType="{x:Type TextBox}">
<Style.Triggers>
<DataTrigger Binding="{Binding MyTextProperty}" Value="{x:Null}">
<Setter Property="Text" Value="Hey, the text should not be empty!" />
<Setter Property="Foreground" Value="Red" />
</DataTrigger>
</Style.Triggers>
</Style>
</TextBlock.Style>
</TextBlock>
问题1:为什么<Style TargetType="{x:Type TextBox}">
给出错误The type 'x:Type' was not found. Verify that you are not missing an assembly reference and that all referenced assemblies have been built.
问题 2:为什么我会收到错误消息The attachable property 'Triggers' was not found in type 'Style'.
我错过了什么吗?
您似乎正在尝试在 Silverlight 中使用 WPF XAML。 Silverlight 不支持{x:Type}
标记扩展。您可以改为使用TargetType={TextBox}
.
另外,Silverlight 没有DataTrigger
支持!
See:
Silverlight 中 DataTrigger 的替代品是什么 https://stackoverflow.com/questions/3529508/what-is-the-replacement-for-datatrigger-in-silverlight
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)