tags:

views:

22

answers:

1

Hello everyone,

I have an user control, It is editable text block. The content of the control is:

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

Also i have another window with tree view:

When treeView1_KeyDown fires I set IsInEditMode to true, but it seems that trigger doesn't work, because content template don't change. Anyone, please explain me why?

A: 

Have you tried removing the default setter?

i.e. change your style code to:

<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>
Robin