zoukankan      html  css  js  c++  java
  • UWP VisualStateManager

    前言

    刘铁猛老师UWP教程学习笔记

    VisualStateManager

    1. VisualStateManager和它的小伙伴们
      1. VisualStateGroup一组与组之间的状态可以叠加使用
      2. VisualState-由Trigger或后台代码触发,使用动画或者Setter来改变控件的属性
    2. 使用技巧
      1. 尽可能避免在后台代码中操作VisualState
      2. 尽可能把UI逻辑与业务逻辑分开
    3. 示例

    宽度等于700

    宽度小于700

    大于700

    <RelativePanel Padding="5">
            <Rectangle
                x:Name="rect"
                Width="400"
                Height="500"
                Fill="Red" />
            <Rectangle
                x:Name="rect1"
                Height="50"
                Fill="Orange"
                RelativePanel.AlignLeftWith="rect"
                RelativePanel.AlignRightWith="rect"
                RelativePanel.Below="rect" />
    
            <Rectangle
                Height="90"
                Fill="Blue"
                RelativePanel.AlignLeftWith="rect1"
                RelativePanel.AlignRightWith="rect1"
                RelativePanel.Below="rect1" />
            <VisualStateManager.VisualStateGroups>
                <VisualStateGroup>
                    <VisualState>
                        <VisualState.Setters>
                            <!--  附加属性加()  -->
                            <Setter Target="rect1.(RelativePanel.AlignLeftWith)" Value="" />
                            <Setter Target="rect1.(RelativePanel.AlignRightWith)" Value="" />
                            <Setter Target="rect1.(RelativePanel.Below) " Value="" />
                            <Setter Target="rect1.(RelativePanel.RightOf)" Value="rect" />
                            <Setter Target="rect1.Width" Value="150" />
                        </VisualState.Setters>
                        <VisualState.StateTriggers>
                            <AdaptiveTrigger MinWindowWidth="700" />
                        </VisualState.StateTriggers>
                    </VisualState>
                </VisualStateGroup>
            </VisualStateManager.VisualStateGroups>
        </RelativePanel>
    

    自定义VisualStateManager

    1.继承StateTriggerBase

    public class MyTrigger : StateTriggerBase
    {
        public MyTrigger()
        {
            Window.Current.SizeChanged += (s, e) =>
            {
                if (e.Size.Width >= 700)
                {
                    this.SetActive(true);
                }
                else
                {
                    this.SetActive(false);
                }
            };
        }
    

    2.XAML中使用

    <RelativePanel Padding="5">
            <Rectangle
                x:Name="rect"
                Width="400"
                Height="500"
                Fill="Red" />
            <Rectangle
                x:Name="rect1"
                Height="50"
                Fill="Orange"
                RelativePanel.AlignLeftWith="rect"
                RelativePanel.AlignRightWith="rect"
                RelativePanel.Below="rect" />
    
            <Rectangle
                Height="90"
                Fill="Blue"
                RelativePanel.AlignLeftWith="rect1"
                RelativePanel.AlignRightWith="rect1"
                RelativePanel.Below="rect1" />
            <VisualStateManager.VisualStateGroups>
                <VisualStateGroup>
                    <VisualState>
                        <VisualState.Setters>
                            <!--  附加属性加()  -->
                            <Setter Target="rect1.(RelativePanel.AlignLeftWith)" Value="" />
                            <Setter Target="rect1.(RelativePanel.AlignRightWith)" Value="" />
                            <Setter Target="rect1.(RelativePanel.Below) " Value="" />
                            <Setter Target="rect1.(RelativePanel.RightOf)" Value="rect" />
                            <Setter Target="rect1.Width" Value="150" />
                        </VisualState.Setters>
                        <VisualState.StateTriggers>
                            <!--<AdaptiveTrigger MinWindowWidth="700" />-->
                            <local:MyTrigger/>
                        </VisualState.StateTriggers>
                    </VisualState>
                </VisualStateGroup>
            </VisualStateManager.VisualStateGroups>
        </RelativePanel>
    
    登峰造极的成就源于自律
  • 相关阅读:
    设置MYSQL允许用IP访问
    EasyUI中那些不容易被发现的坑——EasyUI重复请求2次的问题
    Oracle初级性能优化总结
    Asp.Net MVC3.0网站统计登录认证的在线人数
    App.config和Web.config配置文件的配置节点的解析
    App.config和Web.config配置文件的自定义配置节点
    Asp.Net Web API 2第十八课——Working with Entity Relations in OData
    win7凭据管理、win7多用户远程登录、主机头设置、nuget.org无法访问
    Asp.Net Web API 2第十七课——Creating an OData Endpoint in ASP.NET Web API 2(OData终结点)
    C#基础知识系列八(const和readonly关键字)
  • 原文地址:https://www.cnblogs.com/fishpond816/p/14880696.html
Copyright © 2011-2022 走看看