当需要 class WPF 的多个实例时,模型内部的 INotifyPropertyChanged

INotifyPropertyChanged inside a Model when needing multiple instances of that class WPF

我有一个 ListView 并且 ListViewItemTemplate 包含一个 文本框ListViewItemSource 是类型 T 的 ObservableCollection,其 Viewmodel 具有 as 的实例属性。视图需要将自身绑定到 T 的特定 属性。(T 存在于多个属性中)

        <ListView ItemSource={Binding SomeObservableCollectionOfTypeT}>
           <ListView.ItemTemplate>
              <DataTemplate>
                   <TextBox Text = {Binding T.Someproperty, UpdateSourceTrigger=PropertyChanged} />
              </DataTemplate>
           </ListView.ItemTemplate>
        </ListView>

起初我在 ViewModel 中将 T 作为内部 class(T 也实现了 INotify属性Changed)但我意识到我需要在多个 ViewModel 中使用这个 class相同的时尚。 T会是这里的模特。

我倾向于避免在模型中使用 INotify属性Changed,因为我认为将视图专门绑定到视图模型是可取的。 这是使用 INotify属性Changed 在模型中有效的确切场景吗? 在像这样的典型情况下,我应该如何处理这种情况,您需要使用 MVVM 设计模式绑定到 ViewModel 中集合内的类型的属性?

I'm inclined to avoid using INotifyPropertyChanged in the Model as I think it is desirable having the View bind to the Viewmodel exclusively.

这取决于你如何定义“模型”。如果它是跨多个应用程序使用的某种域对象,您不应该直接绑定它,而是创建一个实现 INotifyPropertyChanged.

的包装视图模型 class

Is this the exact scenario where using INotifyPropertyChanged is valid in Models?

当然可以,只要“模型”不是领域对象。然后你应该在你的客户端应用程序中用一个视图模型替换它。

How should I approach this situation in a typical situation like this, where you need to bind to Properties of a Type that is inside a collection in your ViewModel using the MVVM Design pattern?

创建一个“子”view 模型 class 实现 INotifyPropertyChanged 并将当前模型对象转换为这种类型,例如通过 属性。