WPF 中不同视图的主细节

发布于 2024-08-29 09:55:23 字数 1296 浏览 0 评论 0原文

如果我将主控和详细信息放在同一视图中,我就可以使主控-详细信息场景正常工作。不过,我希望能够根据用户安全来定制详细信息的呈现。因此,我使用相同的视图模型作为后端,将详细信息部分移至单独的视图。现在,当选择新的主记录时,详细信息无法正确更新。如果两个视图使用相同的视图模型,这不应该很好吗?就像我说的,当代码放在同一个视图中时,它可以正常工作。

详细 XAML:

<ListView x:Name="DoctorOfficesList"
              Grid.Column="1"
              Background="black"
              HorizontalContentAlignment="Stretch"
              IsSynchronizedWithCurrentItem="True"
              ItemsSource="{Binding Path=SelectedDoctor.DoctorOfficesCollection}"
              ItemTemplate="{StaticResource DoctorOfficesListTemplate}">
    </ListView>

掌握 XAML:

<ListBox x:Name="DoctorHeaderList"
             Grid.Column="0"
             MinWidth="200"
             MaxWidth="300"
             Margin="0,0,2,0"
             Background="black"
             ItemsSource="{Binding Path=DoctorsList}"
             SelectedItem="{Binding Path=SelectedDoctor}"
             IsSynchronizedWithCurrentItem="True"
             ItemTemplate="{StaticResource DoctorsListTemplate}"
             ScrollViewer.HorizontalScrollBarVisibility="Hidden">
    </ListBox>

我尝试了多种方法来使其发挥作用。当列表框位于同一视图中时,所有方案都有效。当单独移动时,它们会停止。如果重要的话我也会使用 PRISMv2。

我想我的具体问题是如何让它发挥作用?我真的需要一个活动吗?我认为由于它们绑定到同一个虚拟机,这将是一个简单的事情。

I can get the master-detail scenario to work just fine if I keep the master and details together in the same view. However I want to be able to tailor the details presentation based on user security. Therefore I moved the detail section to a separate view using the same viewmodel as a backend. Now the details dont update properly when a new master record is selected. If the two view are using the same viewmodel, shouldnt this work just fine? Like I said when the code is together in the same view it works ok.

detail XAML:

<ListView x:Name="DoctorOfficesList"
              Grid.Column="1"
              Background="black"
              HorizontalContentAlignment="Stretch"
              IsSynchronizedWithCurrentItem="True"
              ItemsSource="{Binding Path=SelectedDoctor.DoctorOfficesCollection}"
              ItemTemplate="{StaticResource DoctorOfficesListTemplate}">
    </ListView>

Master XAML:

<ListBox x:Name="DoctorHeaderList"
             Grid.Column="0"
             MinWidth="200"
             MaxWidth="300"
             Margin="0,0,2,0"
             Background="black"
             ItemsSource="{Binding Path=DoctorsList}"
             SelectedItem="{Binding Path=SelectedDoctor}"
             IsSynchronizedWithCurrentItem="True"
             ItemTemplate="{StaticResource DoctorsListTemplate}"
             ScrollViewer.HorizontalScrollBarVisibility="Hidden">
    </ListBox>

I have tried several ways to get this to work. All scenarios work when the listboxes are in the same view. When moved separately they stop. If it matters I am using PRISMv2 as well.

I guess my specific question is how do I get this to work? Do i really need an event? I would think since they are tied to the same VM this would be a snap.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

白昼 2024-09-05 09:55:23

您确定两个视图都使用相同的视图模型实例吗?我偶尔会在视图模型中实现一个属性,该属性公开 GetHashCode() 的结果,并在视图中将 TextBlock 绑定到它,只是为了仔细检查以下两件事:应该绑定到同一个实例,实际上是。

Are you sure both views are using the same instance of the view model? I occasionally implement a property in my view model that exposes the result of GetHashCode() and bind a TextBlock to it in the view just to double-check that two things that are supposed to be bound to the same instance actually are.

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