【问题标题】:VisualStateManager silverlightVisualStateManager 银光
【发布时间】:2013-03-17 10:18:12
【问题描述】:

您好,我一直坚持让我的 VisualState 正常工作。我想要实现的是在用户输入上设置边框颜色,所以我要做的是这个

VisualStateManager.GoToState(textbox, "BorderHighlight", false);

情节提要在单独的 VisualStateGroup 中定义

<VisualState x:Name="BorderHighlight" >
    <Storyboard >
        <ColorAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:05"  
            Storyboard.TargetName="Border" Storyboard.TargetProperty="        
               (Border.BorderBrush).(SolidColorBrush.Color)">
                   ...
         </ColorAnimationUsingKeyFrames>
    </Storyboard>
</VisualState>

问题是文本框现在没有离开视觉状态,所以它不能被第二次触发。所以我必须以某种方式将其切换回正常状态。我尝试添加一个正常状态 到组看来这是不允许的(只能有一个正常状态?) 我还尝试设置一个正常状态,就像我在第一个完成后设置高亮状态一样,但也没有用。

如果有人能在这里指出正确的方向,我将不胜感激。

【问题讨论】:

    标签: c# silverlight xaml visualstatemanager


    【解决方案1】:

    我假设您正在创建自定义控件。我会有这样的东西:

    <VisualStateManager.VisualStateGroups>
        <VisualStateGroup x:Name="BorderStates">
    
            <VisualState x:Name="BorderHighlight">
                <Storyboard> ... </Storyboard>
            </VisualState>
    
            <VisualState x:Name="BorderNormal">
                <Storyboard> ...  </Storyboard>
            </VisualState>
    
        </VisualStateGroup>
        ...
    </VisualStateManager.VisualStateGroups>
    

    然后响应控件实现中的事件,例如

    protected override void OnMouseEnter(MouseEventArgs e)
    {
        VisualStateManager.GoToState(this, "BorderHighlight, false);
        ...
    }
    
    protected override void OnMouseLeave(MouseEventArgs e)
    {
        VisualStateManager.GoToState(this, "BorderNormal, false);
        ...
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-12-02
      • 2011-05-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多