缺少Style.Triggers和x:类型。为什么?

时间:2011-05-17 08:37:38

标签: silverlight xaml triggers

<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'.

我错过了什么吗?

1 个答案:

答案 0 :(得分:11)

看起来您正在尝试在Silverlight中使用WPF XAML。 Silverlight不支持{x:Type}标记扩展。您可以使用TargetType={TextBox}

此外,Silverlight没有DataTrigger支持!

请参阅:

What is the replacement for DataTrigger in Silverlight

相关问题