我正在设计菜单,我在VariableSizedWrapGrid中有项目列表,如图所示。

我想改变当前活动元素在MouseOver上的边框厚度,我也想改变标题‘业务’的前景颜色。我应该如何在使用MVVM的UWP中实现这一点?
我所知道的是:
对于VariableSizedWrapGrid的项目,这将非常有效。但我有3个项目,如上文所示。我是否需要用3个ViewModel属性创建3个命令,将边框厚度绑定到相应的项?
发布于 2016-08-02 10:55:25
除非您有真正的理由从视图模型中设置BorderWidth (例如,计算的宽度取决于视图模型/模型的其他属性),否则您可以简单地编辑默认的GridViewItem样式并使用VisualStateManager处理PointerOver事件。
您可以在磁盘上找到默认样式,每个SDK版本都有一个文件。
C:\程序文件(x86)\Windows Kits\10\DesignTime\CommonConfiguration\Neutral\UAP\10.0.10240.0\Generic\generic.xaml C:\Program (x86)\Windows Kits\10\DesignTime\CommonConfiguration\Neutral\UAP\10.0.10586.0\Generic\generic.xaml
或者您也可以在MSDN上找到它们,比如用于GridViewItem的。你也可以编辑混合中的现有样式。
您将以具有名称(x:Key)的自定义样式结束,您可以在VariableSizedGrid的GridViewItem上使用它。您必须编辑的样式中的部分处于PointerOver可视状态:
<VisualState x:Name="PointerOver">
<Storyboard>
<DoubleAnimation Storyboard.TargetName="BorderRectangle"
Storyboard.TargetProperty="Opacity"
Duration="0"
To="1"/>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="BorderRectangle" Storyboard.TargetProperty="Stroke">
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightListLowBrush}" />
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter" Storyboard.TargetProperty="Foreground">
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlForegroundBaseHighBrush}" />
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="FocusVisualBlack" Storyboard.TargetProperty="Stroke">
<DiscreteObjectKeyFrame KeyTime="0" Value="Transparent" />
</ObjectAnimationUsingKeyFrames>
<PointerUpThemeAnimation Storyboard.TargetName="ContentPresenter" />
</Storyboard>
</VisualState>如您所见,状态已经更改了Opacity和Stroke,只需为BorderThickness属性添加另一个DoubleAnimation即可。其他州将使用默认值。
https://stackoverflow.com/questions/38716877
复制相似问题