zoukankan      html  css  js  c++  java
  • WP7备注(38)(VisualStateManager)

    TemplateVisualStateAttribute:

    [TemplateVisualStateAttribute(Name = "Disabled", GroupName = "CommonStates")]
    [TemplateVisualStateAttribute(Name = "Normal", GroupName = "CommonStates")]
    [TemplateVisualStateAttribute(Name = "MouseOver", GroupName = "CommonStates")]
    [TemplateVisualStateAttribute(Name = "Pressed", GroupName = "CommonStates")]
    [TemplateVisualStateAttribute(Name = "Unfocused", GroupName = "FocusStates")]
    [TemplateVisualStateAttribute(Name = "Focused", GroupName = "FocusStates")]
    public class Button : ButtonBase

    具体使用:

    <phone:PhoneApplicationPage.Resources>
    <ControlTemplate x:Key="buttonTemplate" TargetType="Button">
    <Grid>
    <VisualStateManager.VisualStateGroups>
    <VisualStateGroup x:Name="CommonStates">
    <VisualState x:Name="Normal" />
    <VisualState x:Name="MouseOver" />
    <VisualState x:Name="Pressed">
    <Storyboard>
    <ObjectAnimationUsingKeyFrames
    Storyboard.TargetName="border"
    Storyboard.TargetProperty="Background">
    <DiscreteObjectKeyFrame KeyTime="0:0:0"
    Value="{StaticResource PhoneForegroundBrush}" />
    </ObjectAnimationUsingKeyFrames>
    <ObjectAnimationUsingKeyFrames
    Storyboard.TargetName="contentControl"
    Storyboard.TargetProperty="Foreground">
    <DiscreteObjectKeyFrame KeyTime="0:0:0"
    Value="{StaticResource PhoneBackgroundBrush}" />
    </ObjectAnimationUsingKeyFrames>
    </Storyboard>
    </VisualState>
    <VisualState x:Name="Disabled">
    <Storyboard>
    <DoubleAnimation Storyboard.TargetName="disableRect"
    Storyboard.TargetProperty="Opacity"
    To="0.6" Duration="0:0:0" />
    </Storyboard>
    </VisualState>
    </VisualStateGroup>
    </VisualStateManager.VisualStateGroups>
    <Border Name="border"
    BorderBrush="{TemplateBinding BorderBrush}"
    BorderThickness="{TemplateBinding BorderThickness}"
    Background="{TemplateBinding Background}"
    CornerRadius="12">
    <ContentControl Name="contentControl"
    Content="{TemplateBinding Content}"
    ContentTemplate="{TemplateBinding ContentTemplate}"
    Margin="{TemplateBinding Padding}"
    HorizontalAlignment="{TemplateBinding
    HorizontalContentAlignment}"
    VerticalAlignment="{TemplateBinding
    VerticalContentAlignment}" />
    </Border>
    <Rectangle Name="disableRect"
    Fill="{StaticResource PhoneBackgroundBrush}"
    Opacity="0" />
    </Grid>
    </ControlTemplate>
    <Style x:Key="buttonStyle" TargetType="Button">
    <Setter Property="BorderBrush" Value="{StaticResource PhoneAccentBrush}" />
    <Setter Property="BorderThickness" Value="6" />
    <Setter Property="Background" Value="{StaticResource PhoneChromeBrush}" />
    <Setter Property="Template" Value="{StaticResource buttonTemplate}" />
    </Style>
    </phone:PhoneApplicationPage.Resources>

    状态跳转:

    VisualStateManager.GoToElementState(UIElemnt, "Normal", true);

  • 相关阅读:
    CCNA 6.9
    CCNA 6.5
    Google search
    CCNA 4.14 TP Correction
    CCNA 6.3
    CCNA 6.6
    有关 英语学习的一些网站
    法语学习笔记
    垃圾邮件分类(Scala 版本)
    SQL 面试经典问题 行列互相转化
  • 原文地址:https://www.cnblogs.com/otomii/p/2041086.html
Copyright © 2011-2022 走看看