0

我想为我创建的边框添加悬停效果,如下所示。

<Border x:Name="borderHeader" Background="#000000" Height="100" VerticalAlignment="top" Opacity="0.5" HorizontalAlignment="Left" Width="1366">

我的视觉状态代码如下。

<VisualStateManager.VisualStateGroups>
<VisualState x:Name="PointerOver">

                    <Storyboard>
                        <DoubleAnimation Duration="0" To="1.0" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="borderHeader"/>
                    </Storyboard>
                </VisualState>
            </VisualStateGroup>
</VisualStateManager.VisualStateGroups>

怎么也行不通。请指出我做错了哪一部分。谢谢

4

1 回答 1

0

视觉状态可以应用于内部的那些控件ControlTemplate。边界是独立的控制。所以你需要依赖PointerEntered&PointerExited事件。

XAML

<Border x:Name="borderHeader" Background="Yellow" Height="100" VerticalAlignment="top" Opacity="0.5" HorizontalAlignment="Left" Width="1366"
                PointerEntered="borderHeader_PointerEntered_1" PointerExited="borderHeader_PointerExited_1"/>

C#

private void borderHeader_PointerEntered_1(object sender, Windows.UI.Xaml.Input.PointerRoutedEventArgs e)
{
    borderHeader.Opacity = 1;
}

private void borderHeader_PointerExited_1(object sender, Windows.UI.Xaml.Input.PointerRoutedEventArgs e)
{
    borderHeader.Opacity = 0.5;
}
于 2013-08-30T03:40:36.553 回答