首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >VisualStateManager和MVVM

VisualStateManager和MVVM
EN

Stack Overflow用户
提问于 2013-05-24 07:20:35
回答 1查看 418关注 0票数 0

我正在开发一个Windows8Store应用程序(使用Grid模板),当我从服务器加载数据时,我想要显示一个ProgressRing并隐藏GridViewListView (取决于应用程序是否被抢断),该应用程序将在数据满载后显示数据。

问题是,当ViewModel加载数据时,我需要能够更改VisualState。

我找到了我认为是解决方案的这里,但是这段代码不会构建。

代码语言:javascript
复制
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可以管理“已崩溃”和“完全”状态。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-05-24 07:46:19

为什么不简单地使用数据处理程序绑定到视图模型属性(如IsBusy {get;set;} )来启用您的Progressring?

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16729637

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档