MouseDoubleClick路由事件不会在EventTrigger中启动

时间:2014-10-30 16:50:44

标签: c# wpf mvvm

我的问题很简单,因为它适用于其他情况但不适用于双击鼠标事件。我想制作可编辑的标签项,它几乎完成了。也许代码会清除这种情况:

<StackPanel Orientation="Horizontal">
        <TextBox x:Name="HeaderEditMode" Text="{Binding Header, Mode=TwoWay}" Visibility="Collapsed" />
        <TextBlock x:Name="HeaderDisplayMode" Text="{Binding Header, Mode=TwoWay}" />
        <StackPanel.Triggers>
            <EventTrigger RoutedEvent="MouseDoubleClick">
                <BeginStoryboard>
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="HeaderEditMode"
                                                       Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="{x:Static Visibility.Visible}" />
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="HeaderDisplayMode"
                                                       Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="{x:Static Visibility.Collapsed}" />
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </BeginStoryboard>
            </EventTrigger>
            <EventTrigger RoutedEvent="MouseLeave">
                <BeginStoryboard>
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="HeaderEditMode"
                                                       Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="{x:Static Visibility.Collapsed}" />
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="HeaderDisplayMode"
                                                       Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="{x:Static Visibility.Visible}" />
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </BeginStoryboard>
            </EventTrigger>
        </StackPanel.Triggers>
    </StackPanel>

如果您将MouseDoubleClick更改为例如MouseDown或MouseEnter,它可以完美地运行。有什么建议吗?

1 个答案:

答案 0 :(得分:0)

尝试将TextBlock包裹在ContentControl中,然后将MouseDoubleClick触发器附加到该{。}}。