加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

数据绑定 – Windows应用商店应用中条件样式(或Style.Triggers-&

发布时间:2020-12-14 05:41:33 所属栏目:Windows 来源:网络整理
导读:我已经用尽了互联网搜索,似乎找不到基于数据绑定条件设计 Windows Store App XAML元素的最佳实践? Style.Triggers DataTrigger … / DataTrigger /Style.Triggersu0026gt;在Windows 8商店应用程序中似乎不像在WPF中那样可用,而Visual State Manager仅用于
我已经用尽了互联网搜索,似乎找不到基于数据绑定条件设计 Windows Store App XAML元素的最佳实践?

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

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

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

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

谢谢大家.

解决方法

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以获取此示例.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读