简体   繁体   English

如何设置 static 资源的依赖属性?

[英]How to set a dependency property of a static resource?

I would like to add a reference to my model in my view model using XAML.我想使用 XAML 在我的观点 model 中添加对我的 model 的引用。 I have defined my model and my view model as resources, and I would like to bind the dependency property Model of the resource myViewModel to the resource myModel.我已将我的 model 和我的视图 model 定义为资源,我想将资源 myViewModel 的依赖属性 Model 绑定到资源 myModel。

How do I do this using XAML?如何使用 XAML 执行此操作?

Below is my attempt:以下是我的尝试:

<Window.Resources>
    <local:ViewModel x:Key="myViewModel" />
    <local:Model x:Key="myModel" />
</Window.Resources>

<myViewModel Model="{StaticResource myModel}">

This works fine:这工作正常:

<Window.Resources>
    <local:Model x:Key="myModel" />
    <local:ViewModel x:Key="myViewModel" Model="{StaticResource myModel}" />
</Window.Resources>

Assuming, of course, the model data structures are declared appropriately (you didn't provide that context).当然,假设 model 数据结构已正确声明(您没有提供该上下文)。

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

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