【问题标题】:Unable to get SelectedItems through Xceed CheckListBox using MVVM无法使用 MVVM 通过 Xceed CheckListBox 获取 SelectedItems
【发布时间】:2018-03-01 16:41:29
【问题描述】:

我一直在为一些 UI 组件使用 wpf xceed 第三方库。我真的很喜欢 CheckListBox 在屏幕上的显示方式。但是我无法将 selectedItems 绑定到 viewmodel 中的任何属性(setter 永远不会触发)。这是代码-

我正在使用数据提供者从枚举中获取值 -

 <UserControl.Resources>
    <ObjectDataProvider MethodName="GetValues" ObjectType="{x:Type sys:Enum}" x:Key="DeviceClassDataProvider">
        <ObjectDataProvider.MethodParameters>
            <x:Type TypeName="Model:HANDeviceClass" />
        </ObjectDataProvider.MethodParameters>
    </ObjectDataProvider>

然后控件被声明为这样 -

<ext:CheckListBox Focusable="False" SelectedMemberPath="{Binding IsChecked, UpdateSourceTrigger=PropertyChanged}" SelectedItemsOverride="{Binding SelectedDeviceGroups, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" SelectedItem="{Binding SelectedItem, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Grid.Row="1" Grid.RowSpan="7" Grid.Column="4" Padding="5" BorderThickness="0.8" BorderBrush="Gray" ItemsSource="{Binding Source={StaticResource DeviceClassDataProvider}}"/>

我将如何在它的视图模型中获取选定的项目?

任何快速帮助将不胜感激!

提前致谢

【问题讨论】:

    标签: wpf mvvm xceed checklistbox


    【解决方案1】:

    如果 SelectedDeviceGroups 是一个返回 ICollection&lt;HANDeviceClass&gt; 的公共属性,则应该可以工作:

    public ICollection<HANDeviceClass> SelectedDeviceGroups { get; } = new ObservableCollection<HANDeviceClass>();
    

    XAML:

    <ext:CheckListBox ItemsSource="{Binding Source={StaticResource DeviceClassDataProvider}}"
                      SelectedItemsOverride="{Binding SelectedDeviceGroups}" />
    
    <TextBlock Text="{Binding SelectedDeviceGroups.Count}" />
    

    当您分别选中和取消选中项目时,项目将被添加到源集合中或从源集合中删除。

    【讨论】:

    • 好吧,我在设置器处有一个断点,但它从来没有碰到过。似乎吸气剂有效。谢谢:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-05-28
    • 2021-10-06
    • 1970-01-01
    • 1970-01-01
    • 2013-05-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多