缺少Style.Triggers和x:Type。为什么? [英] Missing Style.Triggers and x:Type. Why?
问题描述
<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}>
给出错误找不到类型'x:Type'。确认您没有丢失程序集引用,并且所有引用的程序集均已构建。
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.
问题2:为什么会出现错误在样式类型中找不到附加属性触发器。
Question 2: Why am I getting the error The attachable property 'Triggers' was not found in type 'Style'.
我错过了什么吗?
推荐答案
您似乎正在尝试在Silverlight中使用WPF XAML。 Silverlight不支持 {x:Type}
标记扩展。您可以改用 TargetType = {TextBox}
。
It looks like you are trying to use WPF XAML within Silverlight. Silverlight does not support the {x:Type}
markup extension. You can instead use TargetType={TextBox}
.
此外,Silverlight没有 DataTrigger
支持!
Also, Silverlight does not have DataTrigger
support!
请参阅:
Silverlight中DataTrigger的替代品是什么
这篇关于缺少Style.Triggers和x:Type。为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!