WPF/Silverlight 状态 - 从 XAML 激活? [英] WPF/Silverlight States - Activate from XAML?

查看:28
本文介绍了WPF/Silverlight 状态 - 从 XAML 激活?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个简单的问题:是否可以从 XAML 激活视图状态?我只能使用 VisualStateManager.GotoState() 方法从 CS 激活一个.如果很容易,这将解决我的一些 MVVM 问题.

Kind of a quick question: Is it possible to activate a viewstate from XAML? I have been only able to activate one from CS, using the VisualStateManager.GotoState() method. This would fix some of my MVVM issues if it were easily possible.

谢谢

推荐答案

如果您熟悉 Blend 行为、触发器和操作,则可以使用 GoToStateAction,它是 Microsoft.Expression.Interactivity.Core 命名空间的一部分.您将不得不引用作为 Blend 一部分的交互程序集SDK.

If you are familiar with Blend behaviors, triggers, and actions there is a GoToStateAction which is a part of the Microsoft.Expression.Interactivity.Core namespace. You will have to reference the interactivity assemblies which are part of the Blend SDK.

一旦您设置了引用,就如同指定 GoToStateAction 以对某种触发器做出反应一样简单……所有这些都在 XAML 中.这是一个使用 EventTrigger 触发 Loaded 事件的操作的示例:

Once you have the references set up it's as easy as specifying the GoToStateAction to react to some sort of trigger... all in XAML. Here is an example which fires the action off of the Loaded event using an EventTrigger:

<UserControl x:Class="SilverlightApplication1.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
    xmlns:ic="clr-namespace:Microsoft.Expression.Interactivity.Core;assembly=Microsoft.Expression.Interactions">
    <Grid x:Name="LayoutRoot">
        <i:Interaction.Triggers>
            <i:EventTrigger EventName="Loaded">
                <ic:GoToStateAction StateName="MyVisualState"/>
            </i:EventTrigger>
        </i:Interaction.Triggers>
        ...
    </Grid>
</UserControl>

有关特定 GoToState 操作的更多信息和教程 此处.

More info and tutorial about the specific GoToState action here.

编辑:此答案特定于 Silverlight,不确定 WPF 中是否可用.

EDIT: This answer is specific to Silverlight, not sure if this is available in WPF.

这篇关于WPF/Silverlight 状态 - 从 XAML 激活?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆