数据绑定 – Windows应用商店应用中条件样式(或Style.Triggers-> DataTrigger等效)的最佳实践?

前端之家收集整理的这篇文章主要介绍了数据绑定 – Windows应用商店应用中条件样式(或Style.Triggers-> DataTrigger等效)的最佳实践?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
@H_502_4@
我已经用尽了互联网搜索,似乎找不到基于数据绑定条件设计 Windows Store App XAML元素的最佳实践?

< Style.Triggers>< DataTrigger> …< / DataTrigger>< /Style.Triggers\u0026gt;在Windows 8商店应用程序中似乎不像在WPF中那样可用,而Visual State Manager仅用于预先设置的交互状态,例如MouSEOver不是吗?如何根据我的基础View模型显着更改我的UI?

要创建一个明确回答此问题的方案,更改< TextBlock />的最佳实践/最广泛接受的方法是什么?例如,从一种风格到另一种风格,取决于数据绑定条件?我说风格,因为我知道你可以使用转换器来获得类似颜色的东西,但是如果我的变化变得非常复杂呢?例如,添加边框,字体大小和背景颜色?

我的第二个场景是我想要替换< Path />的数据.标签取决于视图模型条件,这也可能吗?基本上,我有一个’cross’和’tick’XAML路径,并希望根据视图模型属性将它们交换出来.

我试图在可能的情况下坚持MVVM,所以也不希望在我的代码背后硬编码样式引用.

谢谢大家.

@H_502_4@

解决方法

VisualStateManager就是你想要的.从 here开始:

Manages states and the logic for transitioning between states for
controls.

我认为这足以涵盖你想要的东西.

来自同一链接的示例应该为您提供一些想法:

<ControlTemplate TargetType="Button">
  <Grid >
    <VisualStateManager.VisualStateGroups>
      <VisualStateGroup x:Name="CommonStates">

        <VisualStateGroup.Transitions>

          <!--Take one half second to transition to the PointerOver state.-->
          <VisualTransition To="PointerOver" 
                              GeneratedDuration="0:0:0.5"/>
        </VisualStateGroup.Transitions>

        <VisualState x:Name="Normal" />

        <!--Change the SolidColorBrush,ButtonBrush,to red when the
            Pointer is over the button.-->
        <VisualState x:Name="PointerOver">
          <Storyboard>
            <ColorAnimation Storyboard.TargetName="ButtonBrush" 
                            Storyboard.TargetProperty="Color" To="Red" />
          </Storyboard>
        </VisualState>
      </VisualStateGroup>
    </VisualStateManager.VisualStateGroups>
    <Grid.Background>
      <SolidColorBrush x:Name="ButtonBrush" Color="Green"/>
    </Grid.Background>
  </Grid>
</ControlTemplate>

请注意,您还可以从代码中更改VisualStateManager的状态,这一点很重要.请查看默认模板中的LayoutAwarePage.cs以获取此示例.

@H_502_4@ @H_502_4@

猜你在找的Windows相关文章