XAML中的简单悬停效果? [英] Simple hover effect in XAML?

查看:62
本文介绍了XAML中的简单悬停效果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我最近对复制此效果的挑战感到沮丧:

So, I was recently frustrated with a challenge to copy this effect:

<style>
a:hover {background-color:yellow; }
</style>

在WinRT中使用XAML实现.

Using the XAML implementation in WinRT.

什么是最冷凝的解决方案?

What is the most condense solution?

推荐答案

好的,这是我的尝试:

<VisualStateManager.VisualStateGroups>
    <VisualStateGroup x:Name="VisualStateGroup">
        <VisualState x:Name="Normal"/>
        <VisualState x:Name="Hover">
            <Storyboard>
                <ColorAnimation To="Yellow" Duration="0"
                    Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)" 
                    Storyboard.TargetName="MyTextBox" />
            </Storyboard>
        </VisualState>
    </VisualStateGroup>
</VisualStateManager.VisualStateGroups>

<Grid x:Name="MyTextBox" Background="White"
        PointerEntered="MyTextBox_PointerEntered" 
        PointerExited="MyTextBox_PointerExited"
        Height="114" Width="537">
</Grid>

这:

private void MyTextBox_PointerEntered(object sender, PointerRoutedEventArgs e)
{
    VisualStateManager.GoToState(this, Hover.Name, false);
}

private void MyTextBox_PointerExited(object sender, PointerRoutedEventArgs e)
{
    VisualStateManager.GoToState(this, Normal.Name, false);
}

但是,肯定有更好的方法!

But, surely there's a better way!

这篇关于XAML中的简单悬停效果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆