触发器不起作用

时间:2010-05-06 16:32:53

标签: wpf triggers

我有一个用户控件,它是可编辑的文本块。该控件的内容是:

                              

    <DataTemplate x:Key="DisplayModeTemplate">
        <TextBlock 
            Text="{Binding ElementName=mainControl, Path=FormattedText}" 
            Margin="5,3,5,3" />
    </DataTemplate>
    <Style TargetType="{x:Type Controls:EditableTextBlock}">
        <Setter Property="ContentTemplate" Value="{StaticResource EditModeTemplate}"/>
        <Style.Triggers>
            <Trigger Property="IsInEditMode" Value="True">
                <Setter Property="ContentTemplate" Value="{StaticResource EditModeTemplate}" />
            </Trigger>
            <Trigger Property="IsInEditMode" Value="False">
                <Setter Property="ContentTemplate" Value="{StaticResource DisplayModeTemplate}" />
            </Trigger>
        </Style.Triggers>
    </Style>
</UserControl.Resources>

我还有另一个树视图窗口:

                                                                                                                                                                                                                                                                    

当treeView1_KeyDown触发时,我将IsInEditMode设置为true,但似乎触发器不起作用,因为内容模板不会更改。有人,请解释一下为什么?

1 个答案:

答案 0 :(得分:0)

您是否尝试删除默认的setter?

即。将您的样式代码更改为:

<Style TargetType="{x:Type Controls:EditableTextBlock}">
    <Style.Triggers>
        <Trigger Property="IsInEditMode" Value="True">
            <Setter Property="ContentTemplate" Value="{StaticResource EditModeTemplate}" />
        </Trigger>
        <Trigger Property="IsInEditMode" Value="False">
            <Setter Property="ContentTemplate" Value="{StaticResource DisplayModeTemplate}" />
        </Trigger>
    </Style.Triggers>
</Style>