WinRT - 边框悬停改变不透明度

时间:2013-08-30 02:41:58

标签: xaml windows-runtime

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

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

但是它无法正常工作。 请告知我哪个部分做错了。 感谢

1 个答案:

答案 0 :(得分:0)

视觉状态可以应用于ControlTemplate内的控件。边境是独立控制。所以你需要依靠PointerEntered&amp; 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;
}
相关问题