有一个快速的问题: 是否可以从XAML激活ViewState?我只能使用VisualStateManager.GotoState()方法从CS中激活它。如果容易实现,这将解决我的MVVM问题。
谢谢
有一个快速的问题: 是否可以从XAML激活ViewState?我只能使用VisualStateManager.GotoState()方法从CS中激活它。如果容易实现,这将解决我的MVVM问题。
谢谢
一旦您设置好引用,只需在XAML中指定GoToStateAction以对某种触发器进行反应即可。以下是一个示例,它使用EventTrigger在Loaded事件上触发该操作:
<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操作,可以在这里获得更多信息和教程。
编辑:此答案仅适用于Silverlight,不确定在WPF中是否可用。