none
控件被隐藏了无法触发Mouse事件了? RRS feed

  • 问题

  • 一个Canvas,floatCanvas,鼠标移动或停留在上面显示出来,移开隐藏

    <UserControl.Resources> <Storyboard x:Key="OnMouseLeave1"> <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="floatCanvas"> <DiscreteObjectKeyFrame KeyTime="0:0:0.3" Value="{x:Static Visibility.Hidden}"/> </ObjectAnimationUsingKeyFrames> </Storyboard> <Storyboard x:Key="OnMouseEnter1"> <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="floatCanvas"> <DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Hidden}"/> <DiscreteObjectKeyFrame KeyTime="0:0:0.3" Value="{x:Static Visibility.Visible}"/> </ObjectAnimationUsingKeyFrames> </Storyboard> <Storyboard x:Key="OnMouseMove1"> <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="floatCanvas"> <DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Hidden}"/> <DiscreteObjectKeyFrame KeyTime="0:0:0.3" Value="{x:Static Visibility.Visible}"/> </ObjectAnimationUsingKeyFrames> </Storyboard> </UserControl.Resources> <UserControl.Triggers> <EventTrigger RoutedEvent="Mouse.MouseLeave" SourceName="floatCanvas"> <BeginStoryboard Storyboard="{StaticResource OnMouseLeave1}"/> </EventTrigger> <EventTrigger RoutedEvent="Mouse.MouseEnter" SourceName="floatCanvas"> <BeginStoryboard x:Name="OnMouseEnter1_BeginStoryboard" Storyboard="{StaticResource OnMouseEnter1}"/> </EventTrigger> <EventTrigger RoutedEvent="Mouse.MouseMove" SourceName="floatCanvas"> <BeginStoryboard x:Name="OnMouseMove1_BeginStoryboard" Storyboard="{StaticResource OnMouseMove1}"/> </EventTrigger> </UserControl.Triggers>


    曾经有一段时间弄过WPF,不过都是像做WinForm一样用WPF,没体现出其意义,现有一个WPF用户控件需要维护,其中就有这么一个效果

    但是发觉隐藏了之后就不会显示出来了

    分别是 MouseLeave MouseEnter MouseMove,这几个我都试了,隐藏了之后在移动上去或停留在上面,无法再次显示

    请问大家,是否可以指出我的问题,或者说,这个效果可以用更简单的方式去实现,谢谢

    2012年9月18日 9:46

全部回复

  • 一个Canvas,floatCanvas,鼠标移动或停留在上面显示出来,移开隐藏

    <UserControl.Resources> <Storyboard x:Key="OnMouseLeave1"> <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="floatCanvas"> <DiscreteObjectKeyFrame KeyTime="0:0:0.3" Value="{x:Static Visibility.Hidden}"/> </ObjectAnimationUsingKeyFrames> </Storyboard> <Storyboard x:Key="OnMouseEnter1"> <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="floatCanvas"> <DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Hidden}"/> <DiscreteObjectKeyFrame KeyTime="0:0:0.3" Value="{x:Static Visibility.Visible}"/> </ObjectAnimationUsingKeyFrames> </Storyboard> <Storyboard x:Key="OnMouseMove1"> <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="floatCanvas"> <DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Hidden}"/> <DiscreteObjectKeyFrame KeyTime="0:0:0.3" Value="{x:Static Visibility.Visible}"/> </ObjectAnimationUsingKeyFrames> </Storyboard> </UserControl.Resources> <UserControl.Triggers> <EventTrigger RoutedEvent="Mouse.MouseLeave" SourceName="floatCanvas"> <BeginStoryboard Storyboard="{StaticResource OnMouseLeave1}"/> </EventTrigger> <EventTrigger RoutedEvent="Mouse.MouseEnter" SourceName="floatCanvas"> <BeginStoryboard x:Name="OnMouseEnter1_BeginStoryboard" Storyboard="{StaticResource OnMouseEnter1}"/> </EventTrigger> <EventTrigger RoutedEvent="Mouse.MouseMove" SourceName="floatCanvas"> <BeginStoryboard x:Name="OnMouseMove1_BeginStoryboard" Storyboard="{StaticResource OnMouseMove1}"/> </EventTrigger> </UserControl.Triggers>


    曾经有一段时间弄过WPF,不过都是像做WinForm一样用WPF,没体现出其意义,现有一个WPF用户控件需要维护,其中就有这么一个效果

    但是发觉隐藏了之后就不会显示出来了

    分别是 MouseLeave MouseEnter MouseMove,这几个我都试了,隐藏了之后在移动上去或停留在上面,无法再次显示

    请问大家,是否可以指出我的问题,或者说,这个效果可以用更简单的方式去实现,谢谢

    而且Canvas作为容器控件,不设背景色,Mouse事件在显示中貌似也不会触发

    2012年9月19日 3:12
  • 当控件的Visibility属性设置为Hidden时,不能触发MouseEnter事件。

    你应当使用Opacity来实现你的动画效果,下面是一个简单的示例:

            <Rectangle Name="rect" Fill="Green" Width="200" Height="200" Opacity="0">
                <Rectangle.Resources>
                    <Storyboard x:Key="OnMouseLeave">
                        <DoubleAnimation From="1" To="0" Duration="0:0:0.3" Storyboard.TargetProperty="Opacity" />
                    </Storyboard>
                    <Storyboard x:Key="OnMouseEnter">
                        <DoubleAnimation From="0" To="1" Duration="0:0:0.3" Storyboard.TargetProperty="Opacity" />
                    </Storyboard>
                </Rectangle.Resources>
                <Rectangle.Triggers>
                    <EventTrigger RoutedEvent="Mouse.MouseLeave">
                        <BeginStoryboard Storyboard="{StaticResource OnMouseLeave}"/>
                    </EventTrigger>
                    <EventTrigger RoutedEvent="Mouse.MouseEnter">
                        <BeginStoryboard Storyboard="{StaticResource OnMouseEnter}"/>
                    </EventTrigger>
                </Rectangle.Triggers>
            </Rectangle>


    Wanpeng wanpeng.ones@gmail.com

    2012年9月19日 3:13
  • 一个Canvas,floatCanvas,鼠标移动或停留在上面显示出来,移开隐藏

    <UserControl.Resources> <Storyboard x:Key="OnMouseLeave1"> <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="floatCanvas"> <DiscreteObjectKeyFrame KeyTime="0:0:0.3" Value="{x:Static Visibility.Hidden}"/> </ObjectAnimationUsingKeyFrames> </Storyboard> <Storyboard x:Key="OnMouseEnter1"> <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="floatCanvas"> <DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Hidden}"/> <DiscreteObjectKeyFrame KeyTime="0:0:0.3" Value="{x:Static Visibility.Visible}"/> </ObjectAnimationUsingKeyFrames> </Storyboard> <Storyboard x:Key="OnMouseMove1"> <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="floatCanvas"> <DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Hidden}"/> <DiscreteObjectKeyFrame KeyTime="0:0:0.3" Value="{x:Static Visibility.Visible}"/> </ObjectAnimationUsingKeyFrames> </Storyboard> </UserControl.Resources> <UserControl.Triggers> <EventTrigger RoutedEvent="Mouse.MouseLeave" SourceName="floatCanvas"> <BeginStoryboard Storyboard="{StaticResource OnMouseLeave1}"/> </EventTrigger> <EventTrigger RoutedEvent="Mouse.MouseEnter" SourceName="floatCanvas"> <BeginStoryboard x:Name="OnMouseEnter1_BeginStoryboard" Storyboard="{StaticResource OnMouseEnter1}"/> </EventTrigger> <EventTrigger RoutedEvent="Mouse.MouseMove" SourceName="floatCanvas"> <BeginStoryboard x:Name="OnMouseMove1_BeginStoryboard" Storyboard="{StaticResource OnMouseMove1}"/> </EventTrigger> </UserControl.Triggers>


    曾经有一段时间弄过WPF,不过都是像做WinForm一样用WPF,没体现出其意义,现有一个WPF用户控件需要维护,其中就有这么一个效果

    但是发觉隐藏了之后就不会显示出来了

    分别是 MouseLeave MouseEnter MouseMove,这几个我都试了,隐藏了之后在移动上去或停留在上面,无法再次显示

    请问大家,是否可以指出我的问题,或者说,这个效果可以用更简单的方式去实现,谢谢

    而且Canvas作为容器控件,不设背景色,Mouse事件在显示中貌似也不会触发

    2012年9月19日 3:14
  • 一个Canvas,floatCanvas,鼠标移动或停留在上面显示出来,移开隐藏

    <UserControl.Resources> <Storyboard x:Key="OnMouseLeave1"> <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="floatCanvas"> <DiscreteObjectKeyFrame KeyTime="0:0:0.3" Value="{x:Static Visibility.Hidden}"/> </ObjectAnimationUsingKeyFrames> </Storyboard> <Storyboard x:Key="OnMouseEnter1"> <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="floatCanvas"> <DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Hidden%

    2012年9月19日 3:15