如何获取由MEF容器创建的ViewModel的实例引用?

时间:2011-03-22 21:04:52

标签: c# wpf silverlight prism mef

WPF Prism app的View在MEF容器的帮助下获取其ViewModel实例:

    [Import]
    public MyModuleViewModel ViewModel
    {
        set { this.DataContext = value; }
    }

如何在View的代码隐藏中获取此VieModel实例的引用?

1 个答案:

答案 0 :(得分:4)

var vm = DataContext as MyModuleViewModel;