【发布时间】:2018-10-22 09:30:09
【问题描述】:
我有一个定义 GridView 的 UWP XAML 页面。各个 GridView 项目都是一个网格。像这样的:
<GridView Name="TheGridView" ItemsSource="{x:Bind stuff}">
<GridView.ItemTemplate>
<DataTemplate x:DataType="more stuff">
<Grid Background="{StaticResource TheBlackColor}">
...stuff here...
</Grid>
</DataTemplate>
</GridView.ItemTemplate>
</GridView>
当鼠标悬停在某个项目上时,我想更改网格的背景颜色(从 TheBlackColor 到其他颜色)。我知道我可以将 PointerEntered 和 PointerExited 事件放在 Grid 上,然后在我后面的代码中设置背景属性,但这似乎是 VisualStateManager 的用途。
但是,我不知道如何让 VisualStateManager 工作。如果我在 XAML 中定义视觉状态,那么我假设我仍然会连接到 Grid 上的 PointerEntered 和 PointerExited 事件,但在我后面的代码中,我会调用 GoToState 来切换状态。但是,我不知道如何告诉 GoToState XAML 树中的哪个项目需要更改其视觉状态。我认为我只是将悬停的网格项传递给 GoToState 的第一个参数(它在我的 PointerEntered 事件中作为“发送者”给我)——但我不能因为 GoToState 的第一个参数是一个 Control 和Grid 不是从 Control 派生的。
【问题讨论】:
标签: c# windows-store-apps winrt-xaml uwp-xaml visualstatemanager