WPF/Silverlight States - Activate from XAML?

ぐ巨炮叔叔 提交于 2019-11-28 01:59:31

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.

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>

More info and tutorial about the specific GoToState action here.

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!