silverlight基本使用Visual State Manager

silverlight基本使用Visual State Manager,第1张

概述代码如下: <UserControl x:Class="VsmState.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://sche

代码如下:

<UserControl x:Class="VsmState.MainPage"    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"    xmlns:d="http://schemas.microsoft.com/Expression/blend/2008"    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"    mc:Ignorable="d"    d:DesignHeight="800" d:DesignWIDth="800">    <GrID x:name="LayoutRoot" Background="White">        <GrID.Resources>            <Style x:Key="buttonTemplete" targettype="button">                <Setter Property="Template">                    <Setter.Value>                        <ControlTemplate targettype="button">                            <border x:name="border" WIDth="300" Height="100" Opacity="1" borderThickness="2" >                                  <!--状态组合-->                                <visualstatemanager.VisualStateGroups>                                    <!--单个状态组合-->                                    <VisualStateGroup x:name="commentstate">                                        <!--设置单个的状态组里不同状态切换时的动画时间-->                                        <VisualStateGroup.Transitions>                                            <VisualTransition From="normal" To="MouSEOver" GeneratedDuration="0:0:0.3"></VisualTransition>                                            <VisualTransition From="MouSEOver" To="normal" GeneratedDuration="0:0:0.2"></VisualTransition>                                            <VisualTransition From="MouSEOver" To="pressed" GeneratedDuration="0:0:0.2"></VisualTransition>                                            <VisualTransition From="pressed" To="MouSEOver" GeneratedDuration="0:0:0.2"></VisualTransition>                                        </VisualStateGroup.Transitions>                                        <!--单个状态的动画,下面的x:name不能写错哦,不然无效果-->                                        <VisualState x:name="normal"></VisualState>                                        <VisualState x:name="MouSEOver" >                                            <Storyboard>                                                <DoubleAnimation Storyboard.Targetname="border" Storyboard.TargetProperty="WIDth" To="600"></DoubleAnimation>                                                <DoubleAnimation Storyboard.Targetname="border" Storyboard.TargetProperty="Height" To="120"></DoubleAnimation>                                                <DoubleAnimation Storyboard.Targetname="border" Storyboard.TargetProperty="Opacity" To="0.8"></DoubleAnimation>                                            </Storyboard>                                        </VisualState>                                        <VisualState x:name="pressed">                                            <Storyboard>                                                <DoubleAnimation Storyboard.Targetname="border" Storyboard.TargetProperty="Opacity" To="0.8"></DoubleAnimation>                                                <colorAnimation Storyboard.Targetname="BackgroundBrush" Storyboard.TargetProperty="color" To="lightSkyBlue" />                                                <colorAnimation Storyboard.Targetname="borderBrush" Storyboard.TargetProperty="color" To="Blue" />                                            </Storyboard>                                        </VisualState>                                    </VisualStateGroup>                                </visualstatemanager.VisualStateGroups>                                <!--内容设置.-->                                <ContentPresenter                                                                           HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"                                         VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>                                <!--背景色设置.-->                                <border.Background>                                    <SolIDcolorBrush x:name="BackgroundBrush" color="Gray"/>                                </border.Background>                                <!--边框颜色设置.-->                                <border.borderBrush>                                    <SolIDcolorBrush x:name="borderBrush" color="Black"/>                                </border.borderBrush>                            </border>                        </ControlTemplate>                    </Setter.Value>                </Setter>            </Style>        </GrID.Resources>        <!--button引用buttonTemplate模板.-->        <button  HorizontalAlignment="Center" VerticalAlignment="Center" Content="I'm a button" Style="{StaticResource buttonTemplete}"/>    </GrID></UserControl>
效果有点像androID里面的选择器Seletor
效果如下:

normal状态:

normal--->>>MouSEOver:

MouSEOver--->>>pressed:

总结

以上是内存溢出为你收集整理的silverlight基本使用Visual State Manager全部内容,希望文章能够帮你解决silverlight基本使用Visual State Manager所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1022832.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-23
下一篇 2022-05-23

发表评论

登录后才能评论

评论列表(0条)

保存