繁体   English   中英

在Caliburn Micro中,如何将视图中的元素绑定到ViewModel中的集合成员

[英]In Caliburn Micro How to bind an element in view to a member of collection in ViewModel

我有一个视图,以固定的布局显示许多图块。 假设出于此讨论的目的,共有5个图块。

在我的ViewModel中,我有一个值对象列表,并且我希望View中的图块绑定到这些TileVO对象。 此列表的长度可以大于或小于5。

我希望能够手动告诉View中的每个Tile绑定到ViewModel中List中的特定索引。

下面的示例是伪造的语法,但是它基本上代表了我要完成的工作。

<Tile Content="{Binding Path=TileVOs[1].Content}"/>

有没有办法告诉Caliburn Micro将View元素绑定到ViewModel集合中的特定索引?

要么,

有没有一种使用函数或表达式提供绑定目标的方法?

好的,显然您毕竟可以使用该语法。 它对我不起作用,因为我的VO字段是简单变量,而不是具有getter和setter的属性。

Caliburn.Micro - 如何在 WPF 视图中显示多个项目,来自 ViewModel 继承:导体<object> .Collection.AllActive<div id="text_translate"><p> 我在 WPF 应用程序中使用 Caliburn.Micro 作为我的 MVVM 框架。 我试图在一个页面中包含几个自定义用户控件,这些控件会根据用户交互动态变化。 我了解 CM 约定是 View 将绑定到 ViewModel 中的Items属性。</p><p> 我的问题是:</p><ol><li><p> 如何在我的视图中访问 ViewModel 的Items集合属性中的每个项目?</p></li><li><p> 我可以像通常使用普通 WPF 控件那样将每个项目单独放置在父视图页面上吗?</p></li></ol><p> 视图页面的基本外观如下所示。 <a href="https://i.stack.imgur.com/5vlyX.jpg" rel="nofollow noreferrer">查看页面布局</a></p><p>基本的 ViewModel 代码:</p><pre> public class TestViewModel: Conductor&lt;object&gt;.Collection.AllActive { public TestViewModel() { Items.Add(new CustomUC1ViewModel()); Items.Add(new CustomUC2ViewModel()); Items.Add(new CustomUC3ViewModel()); } //following logic would reassign the Items collection as required }</pre><p> 附加到Items的 ViewModel 将根据用户与父页面和嵌入式用户控件的交互而动态变化。</p><p> 我希望以上内容有意义(这是我的第一篇文章)。</p></div></object>

[英]Caliburn.Micro - How to display multiple items in WPF View from ViewModel that inherits: Conductor<object>.Collection.AllActive

暂无
暂无

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

相关问题 在Caliburn.Micro中如何将动作绑定到嵌套的ViewModel方法? 在 caliburn micro 中绑定视图和模型 使用 Caliburn Micro 将 WebView2 绑定到 ViewModel 如何在Caliburn Micro中处理“无法为viewmodel找到视图”? 如何在Caliburn.Micro中使用View的结果调用ViewModel方法 Caliburn.Micro - 如何在 WPF 视图中显示多个项目,来自 ViewModel 继承:导体<object> .Collection.AllActive<div id="text_translate"><p> 我在 WPF 应用程序中使用 Caliburn.Micro 作为我的 MVVM 框架。 我试图在一个页面中包含几个自定义用户控件,这些控件会根据用户交互动态变化。 我了解 CM 约定是 View 将绑定到 ViewModel 中的Items属性。</p><p> 我的问题是:</p><ol><li><p> 如何在我的视图中访问 ViewModel 的Items集合属性中的每个项目?</p></li><li><p> 我可以像通常使用普通 WPF 控件那样将每个项目单独放置在父视图页面上吗?</p></li></ol><p> 视图页面的基本外观如下所示。 <a href="https://i.stack.imgur.com/5vlyX.jpg" rel="nofollow noreferrer">查看页面布局</a></p><p>基本的 ViewModel 代码:</p><pre> public class TestViewModel: Conductor&lt;object&gt;.Collection.AllActive { public TestViewModel() { Items.Add(new CustomUC1ViewModel()); Items.Add(new CustomUC2ViewModel()); Items.Add(new CustomUC3ViewModel()); } //following logic would reassign the Items collection as required }</pre><p> 附加到Items的 ViewModel 将根据用户与父页面和嵌入式用户控件的交互而动态变化。</p><p> 我希望以上内容有意义(这是我的第一篇文章)。</p></div></object> Caliburn Micro事件在视图/ viewmodel关闭 Caliburn.View模型的微视图分辨率<T> Caliburn Micro-将ListBox绑定到集合中对象的属性 caliburn.micro绑定元素对viewmodel函数的可见性,而不是属性
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM