Я непосредственно начинаю с картинки, показывающей структуру, которая у меня есть, чтобы я мог задать свой вопрос, используя картинку.
![relation between the ViewModels](https://i.stack.imgur.com/cjHq0.png)
У меня есть ParentModel
, как это:
Public Class ParentModel
public Property ModelValue_A As String
Public Property ModelValue_B As String
End Class
У меня есть ParentViewModel
, который имеет два свойстватипа ChildViewModel
.
Public Class ParentViewModel
Public Property Parent As ParentModel
Public Property ChildViewModel_A As ChildViewModel
Public Property ChildViewModel_B As ChildViewModel
Sub New
ChildViewModel_A = New ChildViewModel()
ChildViewModel_B = New ChildViewModel()
End Sub
End Class
Мой ParentView
выглядит следующим образом:
<DataTemplate>
<StackPanel Orientation="Horizontal">
<ContentPresenter Content="{Binding ChildViewModel_A}"/>
<ContentPresenter Content="{Binding ChildViewModel_B}"/>
</StackPanel>
</DataTemplate>
Мой ChildViewModel
выглядит следующим образом:
Public Class ChildViewModel
Private _ChildValue As String
Public Property ChildValue As String
Get
Return _ChildValue
End Get
Set
_ChildValue = Value
NotifyPropertyChanged(NameOf(ChildValue))
End Set
End Class
МойChildView
выглядит следующим образом:
<DataTemplate>
<TextBox Text="{Binding ChildValue}" />
</DataTemplate>
Мой NotifyPropertyChanged
метод:
Public Event PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged
Protected Sub NotifyPropertyChanged(info As [String])
RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(info))
End Sub
Когда я запускаю приложение, я получаю вид, аналогичный изображенному выше.Там я могу изменить ChildValue
, набрав TextBox
из ChildView
.Тем не менее, у меня все еще нет связи / отношения между каждым ChildValue
с соответствующим свойством ParentViewModel
: ChildViewModel_A
и ChildViewModel_B
.
Мой вопрос :Как я могу изменить ModelValue_A
, изменив ChildValue
из ChildViewModel_A
, и, соответственно, изменить ModelValue_B
, изменив ChildValue
из ChildViewModel_B
?