缺少 Style.Triggers 和 x:Type。为什么?
<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:为什么 给出错误
The type 'x:Type' was not found.验证您没有缺少程序集引用,并且所有引用的程序集均已构建。
问题 2:为什么我收到错误在“Style”类型中找不到可附加属性“触发器”。< /code>
我错过了什么吗?
<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>
Question 1: Why is <Style TargetType="{x:Type TextBox}">
giving the error The type 'x:Type' was not found. Verify that you are not missing an assembly reference and that all referenced assemblies have been built.
Question 2: Why am I getting the error The attachable property 'Triggers' was not found in type 'Style'.
Am I missing anything ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您似乎正在尝试在 Silverlight 中使用 WPF XAML。 Silverlight 不支持
{x:Type}
标记扩展。您可以改为使用TargetType={TextBox}
。另外,Silverlight 不支持
DataTrigger
!请参阅:
Silverlight 中 DataTrigger 的替代品是什么
It looks like you are trying to use WPF XAML within Silverlight. Silverlight does not support the
{x:Type}
markup extension. You can instead useTargetType={TextBox}
.Also, Silverlight does not have
DataTrigger
support!See:
What is the replacement for DataTrigger in Silverlight