谁能提供Conductor.Collection.AllActive用法的任何简单工作示例?

编程入门 行业动态 更新时间:2024-10-10 06:19:21
本文介绍了谁能提供Conductor.Collection.AllActive用法的任何简单工作示例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

有点奇怪,但是我真的在任何地方都找不到可行的示例。

It's a bit strange, but I really can't find a working example anywhere.

顺便说一句,我使用的是ViewModel-first方法(在WPF)。

By the way, I'm using a ViewModel-first approach (in WPF) if this is important.

谢谢。

推荐答案

如果您在此处进行讨论,您会发现AllActive的目的是组成多个Views / ViewModels放入一个包含ViewModel的视图。从您以前的评论来看,似乎这是您所期望的,但是我认为我至少要在这里引用它。

If you have a look at the discussion here you will see that the intent of AllActive is to compose several Views/ViewModels into a containing ViewModel. Judging from your previous comments it seems as if this is what you were expecting but I figured I'd at least reference it here.

您随后提到了在以下位置激活3个不同的ViewModels视图的不同区域。我过去处理此问题的方式是具有单独的属性,用于绑定/引用View中的ViewModel,然后将它们全部添加到Items中以获得导体行为。

You then mention activating 3 different ViewModels at different regions of the View. The way I've handled this in the past is to have separate properties for binding/referencing the ViewModels in the View, and then just adding all of them to Items to get the Conductor behavior.

public sealed class MyViewModel : Conductor<Screen>.Collection.AllActive { public MyViewModel(IMagicViewModelFactory factory) { FirstSubViewModel = factory.MagicallyGiveMeTheViewModelIWant(); SecondSubViewModel = factory.MagicallyGiveMeTheViewModelIWant(); ThirdSubViewModel = factory.MagicallyGiveMeTheViewModelIWant(); Items.Add(FirstSubViewModel); Items.Add(SecondSubViewModel); Items.Add(ThirdSubViewModel); } public Screen FirstSubViewModel { get; private set; } public Screen SecondSubViewModel { get; private set; } public Screen ThirdSubViewModel { get; private set; } }

在MyView中,您会看到类似的内容。当然,您可以在视图中的任何位置放置这些 ContentControls 。

And in MyView you would have something like this. Of course you could put these ContentControls wherever you want to in the view.

<StackPanel> <ContentControl x:Name="FirstSubViewModel" /> <ContentControl x:Name="SecondSubViewModel" /> <ContentControl x:Name="ThirdSubViewModel" /> </StackPanel>

AllActive 的另一个常用用法是有项目清单。但是,这些项目非常复杂,足以保证拥有自己的需要激活的View / ViewModels。在那种情况下,您不必为视图具有单独的属性,只需将列表控件的 x:Name 设置为 Items 。

Another common use for AllActive is when you have a list of items. But the items are complex enough to warrant having their own View/ViewModels that require activation. In that case you would not have to have separate properties for the views as you would just set the x:Name of the list control to Items.

更多推荐

谁能提供Conductor.Collection.AllActive用法的任何简单工作示例?

本文发布于:2023-11-28 19:07:49,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1643602.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:谁能   示例   简单   工作   AllActive

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!