Xaml VisualStateManager和MVVM
我正在使用Windows 8应用商店应用程序(使用网格应用程序模板),当我从服务器加载数据时,我想显示一个Xaml VisualStateManager和MVVM,xaml,mvvm,windows-8,visualstatemanager,Xaml,Mvvm,Windows 8,Visualstatemanager,我正在使用Windows 8应用商店应用程序(使用网格应用程序模板),当我从服务器加载数据时,我想显示一个ProgressRing,并隐藏GridView或ListView(取决于应用程序是否被抓拍)以在完全加载后显示数据 问题是,当ViewModel加载数据时,我需要能够更改VisualState 我发现了我认为是一个解决方案,但这段代码不会生成 public class StateManager : DependencyObject { public static string Ge
ProgressRing
,并隐藏GridView
或ListView
(取决于应用程序是否被抓拍)以在完全加载后显示数据
问题是,当ViewModel加载数据时,我需要能够更改VisualState
我发现了我认为是一个解决方案,但这段代码不会生成
public class StateManager : DependencyObject
{
public static string GetVisualStateProperty(DependencyObject obj)
{
return (string)obj.GetValue(VisualStatePropertyProperty);
}
public static void SetVisualStateProperty(DependencyObject obj, string value)
{
obj.SetValue(VisualStatePropertyProperty, value);
}
public static readonly DependencyProperty VisualStatePropertyProperty =
DependencyProperty.RegisterAttached(
"VisualStateProperty",
typeof(string),
typeof(StateManager),
new PropertyMetadata((s, e) => //this throws the error
{
var propertyName = (string)e.NewValue;
var ctrl = s as Control;
if (ctrl == null)
throw new InvalidOperationException("This attached property only supports types derived from Control.");
System.Windows.VisualStateManager.GoToState(ctrl, (string)e.NewValue, true);
}));
}
错误:无法将lambda表达式转换为类型“object”,因为它是
不是委托类型
有人知道如何使链接的解决方案工作吗?还是有一个我完全不知道的更简单的方法(我是XAML新手!)
我甚至不确定列出的解决方案是否有效,因为“快照”与“完整”状态是由模板中包含的基本
LayoutAwarePage
类管理的。为什么不简单地使用datatrigger绑定到viewmodel属性,如IsBusy{get;set;}要启用您的Progressring?我实际上有一个IsBusy属性,并尝试了该属性,但问题是当进度轮仍在加载时,我的数据开始显示在屏幕上(不完整)。我希望在加载所有数据之前项目视图都是不可见的(当我键入此命令时,我认为这是一个愚蠢的想法,我应该以一种在不完整时仍然有用的方式加载数据)。datatrigger还可以处理项目视图的可见性。