【问题标题】:Why my Storyboard run when I move my cursor from an element to another? [duplicate]当我将光标从一个元素移动到另一个元素时,为什么我的 Storyboard 会运行? [复制]
【发布时间】:2015-01-05 14:27:09
【问题描述】:

我用一个有两个按钮的面板构建了一个小控件。当我悬停控件时,我想显示面板并在我离开时将其隐藏。一切都很好,但我有一个错误。当我将光标从 TextBlock 移动到 Image 时,我的 Storyboard 再次运行。我不明白为什么,因为它们都在控件内。我尝试添加Border 来包装控件,但它不起作用。

<UserControl.Resources>
    <Storyboard x:Key="Show">
        <DoubleAnimationUsingKeyFrames
            Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)"
            Storyboard.TargetName="QuickPanel">
            <EasingDoubleKeyFrame KeyTime="0" Value="18"/>
            <EasingDoubleKeyFrame KeyTime="0:0:0.2" Value="0"/>
        </DoubleAnimationUsingKeyFrames>
    </Storyboard>
    <Storyboard x:Key="Hide">
        <DoubleAnimationUsingKeyFrames
            Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)"
            Storyboard.TargetName="QuickPanel">
            <EasingDoubleKeyFrame KeyTime="0" Value="0"/>
            <EasingDoubleKeyFrame KeyTime="0:0:0.2" Value="18"/>
        </DoubleAnimationUsingKeyFrames>
    </Storyboard>
</UserControl.Resources>

<UserControl.Triggers>
    <EventTrigger RoutedEvent="Border.MouseEnter">
        <BeginStoryboard Storyboard="{StaticResource Show}"/>
    </EventTrigger>
    <EventTrigger RoutedEvent="Border.MouseLeave">
        <BeginStoryboard Storyboard="{StaticResource Hide}"/>
    </EventTrigger>
</UserControl.Triggers>

<Border Width="144" Height="36" ClipToBounds="True" BorderThickness="0">
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition />
        </Grid.ColumnDefinitions>
        <Image Source="http://www.streamplay.fr/thumb/fanart/3000/3000/1321396.jpg"
           VerticalAlignment="Center" HorizontalAlignment="Center" Margin="2"
           Stretch="UniformToFill" Height="34" Width="34"/>
        <Grid Grid.Column="1">
            <StackPanel VerticalAlignment="Center" Margin="6,0,0,0">
                <TextBlock FontSize="12" FontWeight="DemiBold">Sample Title</TextBlock>
                <TextBlock FontSize="10" Text="{Binding Title, Mode=TwoWay}"></TextBlock>
            </StackPanel>
        </Grid>
        <StackPanel x:Name="QuickPanel" Grid.Column="1" Width="18" HorizontalAlignment="Right" RenderTransformOrigin="0.5,0.5">
            <StackPanel.RenderTransform>
                <TransformGroup>
                    <ScaleTransform/>
                    <SkewTransform/>
                    <RotateTransform/>
                    <TranslateTransform X="18"/>
                </TransformGroup>
            </StackPanel.RenderTransform>
            <Button x:Name="button" Height="18" Content="p" IsDefault="True" />
            <Button x:Name="button1" Height="18" Content="k" />
        </StackPanel>
    </Grid>
</Border>

知道如何改变吗?

【问题讨论】:

  • BorderBackground Property设置为Transparent..它会解决你的问题..
  • @AmolBavannavar Set Background Property 有效。你知道为什么吗 ? (添加一个正确的答案,我验证它)
  • 这个问题是重复的。检查上面评论中给出的链接的答案......
  • 我应该关闭这个问题吗?
  • 是的.. 并标记我的评论...

标签: wpf xaml storyboard


【解决方案1】:

您需要为边框元素 UI 设置背景:

边框 Background="透明" ...

如果不设置背景,图片和文本块之间的空间就是你的父窗口。

【讨论】:

    猜你喜欢
    • 2010-11-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-22
    • 2015-03-07
    • 2022-12-03
    • 2020-11-06
    • 1970-01-01
    相关资源
    最近更新 更多