css - XAML 中的简单悬停效果?

标签 css xaml windows-8 microsoft-metro winrt-xaml

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

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

在 WinRT 中使用 XAML 实现。

最简洁的解决方案是什么?

最佳答案

好的,这是我的尝试:

<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);
}

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

关于css - XAML 中的简单悬停效果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11160715/

相关文章:

html - CSS 中的 .class 无法正常工作如何修复?

Jquery:在每第 n 个像素向下滚动后显示 <ul> ("Lazy Loading")

c# - DataBinding 集合和更改集合元素

c++ - Windows 8 下 Metro 风格应用程序的类似 Fraps 功能

c# - 使用数据模板和绑定(bind)数据以编程方式创建列表框

javascript - 使用 JS 和 CSS 更改 DIV 颜色的下拉选择器

html - Bootstrap 对齐 - 导航标题对齐

wpf - 手动将字符串解析为 XAML 属性

c# - 设置用户控件可见性

c# - 如何在 Windows 8 的桌面应用程序中访问 Metro 应用程序的本地存储?