简体   繁体   English

如何从代码访问App.xaml中创建的定位器?

[英]How to access locator that is created in App.xaml from the code?

In my App.xaml the locator instance is created: 在我的App.xaml ,创建了定位器实例:

<Application.Resources>
    <!--Global View Model Locator-->
    <vm:ViewModelLocator x:Key="Locator"
                         d:IsDataSource="True" />
</Application.Resources>

Now I would like to access Locator object from ViewModel . 现在,我想从ViewModel访问Locator对象。 How can I refer to that object from the code? 如何从代码中引用该对象?

像这样:

var locator = (ViewModelLocator) Application.Current.Resources["Locator"];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM