<small id='Vhv47'></small><noframes id='Vhv47'>

<tfoot id='Vhv47'></tfoot>

    • <bdo id='Vhv47'></bdo><ul id='Vhv47'></ul>

      <i id='Vhv47'><tr id='Vhv47'><dt id='Vhv47'><q id='Vhv47'><span id='Vhv47'><b id='Vhv47'><form id='Vhv47'><ins id='Vhv47'></ins><ul id='Vhv47'></ul><sub id='Vhv47'></sub></form><legend id='Vhv47'></legend><bdo id='Vhv47'><pre id='Vhv47'><center id='Vhv47'></center></pre></bdo></b><th id='Vhv47'></th></span></q></dt></tr></i><div id='Vhv47'><tfoot id='Vhv47'></tfoot><dl id='Vhv47'><fieldset id='Vhv47'></fieldset></dl></div>
      1. <legend id='Vhv47'><style id='Vhv47'><dir id='Vhv47'><q id='Vhv47'></q></dir></style></legend>

        如何在可导航的应用程序中支持 ListBox SelectedItems 与 MVVM 的绑定

        时间:2023-10-07
            • <tfoot id='kPY4l'></tfoot>
                <tbody id='kPY4l'></tbody>

                <i id='kPY4l'><tr id='kPY4l'><dt id='kPY4l'><q id='kPY4l'><span id='kPY4l'><b id='kPY4l'><form id='kPY4l'><ins id='kPY4l'></ins><ul id='kPY4l'></ul><sub id='kPY4l'></sub></form><legend id='kPY4l'></legend><bdo id='kPY4l'><pre id='kPY4l'><center id='kPY4l'></center></pre></bdo></b><th id='kPY4l'></th></span></q></dt></tr></i><div id='kPY4l'><tfoot id='kPY4l'></tfoot><dl id='kPY4l'><fieldset id='kPY4l'></fieldset></dl></div>
                  <bdo id='kPY4l'></bdo><ul id='kPY4l'></ul>

                • <legend id='kPY4l'><style id='kPY4l'><dir id='kPY4l'><q id='kPY4l'></q></dir></style></legend>

                  <small id='kPY4l'></small><noframes id='kPY4l'>

                  本文介绍了如何在可导航的应用程序中支持 ListBox SelectedItems 与 MVVM 的绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在制作一个可通过自定义下一步"和后退"按钮和命令导航的 WPF 应用程序(即不使用 NavigationWindow).在一个屏幕上,我有一个 ListBox 必须支持多项选择(使用 Extended 模式).我有这个屏幕的视图模型并将所选项目存储为属性,因为它们需要维护.

                  I am making a WPF application that is navigable via custom "Next" and "Back" buttons and commands (i.e. not using a NavigationWindow). On one screen, I have a ListBox that has to support multiple selections (using the Extended mode). I have a view model for this screen and store the selected items as a property, since they need to be maintained.

                  但是,我知道 ListBoxSelectedItems 属性是只读的.我一直在尝试使用 这个解决方案来解决这个问题,但我无法将它应用到我的实现中.我发现我无法区分何时取消选择一个或多个元素以及何时在屏幕之间导航(在这两种情况下都会引发 NotifyCollectionChangedAction.Remove,因为从技术上讲,在导航离开时所有选定的项目都会被取消选择从屏幕上).我的导航命令位于一个单独的视图模型中,该模型管理每个屏幕的视图模型,因此我无法在其中放置与带有 ListBox 的视图模型相关的任何实现.

                  However, I am aware that the SelectedItems property of a ListBox is read-only. I have been trying to work around the issue using this solution here, but I have not been able to adopt it into my implementation. I found that I can't differentiate between when one or more elements are deselected and when I navigate between screens (NotifyCollectionChangedAction.Remove is raised in both cases, since technically all the selected items are deselected when navigating away from the screen). My navigation commands are located in a separate view model which manages the view models for each screen, so I can't put any implementation related to the view model with the ListBox in there.

                  我发现了其他几个不太优雅的解决方案,但这些似乎都没有强制视图模型和视图之间的双向绑定.

                  I have found several other less elegant solutions, but none of these seem to enforce a two-way binding between the view model and the view.

                  任何帮助将不胜感激.如果有助于理解我的问题,我可以提供一些源代码.

                  Any help would be greatly appreciated. I can provide some of my source code if it would help to understand my problem.

                  推荐答案

                  尝试在每个数据项上创建一个 IsSelected 属性并将 ListBoxItem.IsSelected 绑定到该属性

                  Try creating an IsSelected property on each of your data items and binding ListBoxItem.IsSelected to that property

                  <Style TargetType="{x:Type ListBoxItem}">
                      <Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}" />
                  </Style>
                  

                  这篇关于如何在可导航的应用程序中支持 ListBox SelectedItems 与 MVVM 的绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:将列表框绑定到列表&lt;对象&gt;在 WinForms 中 下一篇:如何将字符串拆分为多个值?

                  相关文章

                    <i id='DIBVD'><tr id='DIBVD'><dt id='DIBVD'><q id='DIBVD'><span id='DIBVD'><b id='DIBVD'><form id='DIBVD'><ins id='DIBVD'></ins><ul id='DIBVD'></ul><sub id='DIBVD'></sub></form><legend id='DIBVD'></legend><bdo id='DIBVD'><pre id='DIBVD'><center id='DIBVD'></center></pre></bdo></b><th id='DIBVD'></th></span></q></dt></tr></i><div id='DIBVD'><tfoot id='DIBVD'></tfoot><dl id='DIBVD'><fieldset id='DIBVD'></fieldset></dl></div>

                      <tfoot id='DIBVD'></tfoot>
                    1. <small id='DIBVD'></small><noframes id='DIBVD'>

                      • <bdo id='DIBVD'></bdo><ul id='DIBVD'></ul>
                    2. <legend id='DIBVD'><style id='DIBVD'><dir id='DIBVD'><q id='DIBVD'></q></dir></style></legend>