我正在开发一个Windows8Store应用程序(使用Grid模板),当我从服务器加载数据时,我想要显示一个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可以管理“已崩溃”和“完全”状态。
发布于 2013-05-24 07:46:19
为什么不简单地使用数据处理程序绑定到视图模型属性(如IsBusy {get;set;} )来启用您的Progressring?
https://stackoverflow.com/questions/16729637
复制相似问题