同一 WPF 窗口和 ViewModel 的多个实例

发布于 2024-10-17 02:55:08 字数 442 浏览 9 评论 0原文

我有一个名为“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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

柳若烟 2024-10-24 02:55:08

发现对视图模型内的类的共享引用。此类在模块中声明并在整个应用程序中保留。这个类包含一个列表,我认为我正在传递给我的 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文