同一 WPF 窗口和 ViewModel 的多个实例
我有一个名为“winAppt.xaml”的窗口和一个名为“ItemViewModel.vb”的视图模型。我希望用户能够打开“winAppt.xaml”窗口的多个实例,以便同时在屏幕上显示不同的帐户。现在的问题是,当“winAppt.xaml”的第二个实例加载时,第一个实例的部分数据被第二个实例替换。
我目前正在做类似的事情
Dim i As New ItemViewModel()
i.Load(itemID)
Dim fDetailRec As New winAppt(i)
fDetailRec.ShowDialog()
,然后将窗口的 DataContext 设置为传入的视图模型。
Public Sub New(ByVal i As ItemViewModel)
Me.DataContext = i
End Sub
I have a window named 'winAppt.xaml' and a view model called 'ItemViewModel.vb'. I would like the user to be able to open multiple instances of the 'winAppt.xaml' window to show different accounts on the screen at once. Problem right now is that when the second instance of 'winAppt.xaml' loads the first instance has some of it's data replaced with the second instance.
I'm currently doing something like this
Dim i As New ItemViewModel()
i.Load(itemID)
Dim fDetailRec As New winAppt(i)
fDetailRec.ShowDialog()
I then set the DataContext of my window to the view model passed in.
Public Sub New(ByVal i As ItemViewModel)
Me.DataContext = i
End Sub
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
发现对视图模型内的类的共享引用。此类在模块中声明并在整个应用程序中保留。这个类包含一个列表,我认为我正在传递给我的 ViewModel,它实际上引用了它。
Found a shared reference to a class inside the view model. This class was declared in a module and persisted throughout the application. This class contained a list that I thought I was passing to my ViewModel, it was really referencing it.