Mvvm 更改鼠标在UWP上的边框厚度

Mvvm 更改鼠标在UWP上的边框厚度,mvvm,uwp,windows-10-universal,uwp-xaml,template10,Mvvm,Uwp,Windows 10 Universal,Uwp Xaml,Template10,我正在设计菜单,在VariableSizedWrapGrid中有项目列表,如图所示。 我想更改鼠标上当前活动元素的边框厚度,也想更改标题“Business”的前景色。 我应该如何使用MVVM在UWP中实现这一点 我知道的是: 在MoseOver上使用交互并调用ViewModel命令 命令将设置VIewModel的BorderWidth属性 BorderWidth属性将绑定到控件的BorderThickness属性 BorderThickness=“{Binding BorderWidth}” 这

我正在设计菜单,在VariableSizedWrapGrid中有项目列表,如图所示。 我想更改鼠标上当前活动元素的边框厚度,也想更改标题“Business”的前景色。 我应该如何使用MVVM在UWP中实现这一点

我知道的是:

  • 在MoseOver上使用交互并调用ViewModel命令

  • 命令将设置VIewModel的BorderWidth属性

  • BorderWidth属性将绑定到控件的BorderThickness属性

    BorderThickness=“{Binding BorderWidth}”


  • 这对于一个VariableSizedWrapGrid的项目非常有用。但我有3个项目如上所示。是否需要创建3个具有3个ViewModel属性的命令,将边框厚度绑定到相应的项目?

    除非您有真正的理由从ViewModel内部设置
    边框宽度(例如,计算宽度取决于viewmodel/模型的其他属性,您只需编辑默认的
    GridViewItem
    样式,并使用
    VisualStateManager
    处理
    指针上方的事件即可

    您可以在磁盘上找到默认样式,每个SDK版本有一个文件

    C:\ProgramFiles(x86)\Windows Kits\10\DesignTime\CommonConfiguration\Neutral\UAP\10.0.10240.0\Generic\Generic.xaml C:\ProgramFiles(x86)\Windows Kits\10\DesignTime\CommonConfiguration\Neutral\UAP\10.0.10586.0\Generic\Generic.xaml

    或者你也可以在MSDN上找到它们,就像一个。你也可以

    您将以一个带有名称(x:Key)的自定义样式结束,您可以在
    VariableSizeGrid
    GridViewItem
    上使用该样式。您必须编辑的样式中的部分处于
    指针上方
    视觉状态:

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

    如您所见,该状态已经更改了
    不透明度
    笔划
    ,只需为
    边界厚度
    属性添加另一个
    DoubleAnimation
    。其他状态将使用默认值。

    这可能是一个UI问题,因此您的VM不应参与其中。感谢正确使用templ使用ViewStateManager和blend创建的ate可编辑控件让我的一天充满乐趣。