0

I'm using the XCeed CheckComboBox: https://wpftoolkit.codeplex.com/wikipage?title=CheckComboBox&referringTitle=Home

In my ComboBox there are some types. All types are listed correctly in the combobox. My problem is, that if I uncheck an item, the set-property of IsFiltered isn't called:

Maddy
  • 570
  • 1
  • 7
  • 27

3 Answers3

0

Most fields that end with MemberPath are looking for a string containing the property name.

In your case, you need

ValueMemberPath="IsFiltered"

instead of

ValueMemberPath="{Binding IsFiltered, Mode=TwoWay}

Right now its looking on your data object for a string property called IsFiltered that will tell it what property name to use for the Value, and since your IsFiltered is a bool, this doesn't work.

Rachel
  • 130,264
  • 66
  • 304
  • 490
  • I think `ValueMemberPath` on this control is used to specify a sub-property of each selected item to include in the `SelectedValue`. I don't think it reflects the selection state, i.e., whether the item was checked. – Mike Strobel Oct 28 '14 at 14:17
  • @MikeStrobel Ah you could be right. I got caught immediately by the incorrect usage of `ValueMemberPath` and did not consider that there may be other problems related to the design and usage of the `CheckedComboBox`. I haven't used XCeed's controls before, so am not sure how they work. – Rachel Oct 28 '14 at 14:45
0

From the docs:

https://xceed.com/wp-content/documentation/xceed-toolkit-plus-for-wpf/Xceed.Wpf.Toolkit~Xceed.Wpf.Toolkit.CheckComboBox.html

And

https://xceed.com/wp-content/documentation/xceed-toolkit-plus-for-wpf/Xceed.Wpf.Toolkit~Xceed.Wpf.Toolkit.Primitives.Selector~SelectedMemberPath.html

You'll need an ObservableCollection and a class holding the IsChecked and Item properties that fire the notifychanged event.

Below the working example: When you click the Set A and C button the items A and C will be checked as expected.

MainWindow.xaml.cs

using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Windows;

namespace WpfApp6
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        private ViewModel viewModel;

        public MainWindow()
        {
            InitializeComponent();

            viewModel = new ViewModel();

            foreach (var item in new string[] { "A", "B", "C", "D"})
            {
                viewModel.CheckComboBoxItems.Add(new CheckComboBoxItems { IsChecked = false, Item = item}); 
            }

            DataContext = viewModel;

        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {   
            foreach (var checkBoxToSet in viewModel.CheckComboBoxItems)
            {
                if (checkBoxToSet.Item.Equals("A") || checkBoxToSet.Item.Equals("C"))
                {
                    checkBoxToSet.IsChecked = true;
                }
            }
        }
    }

    public class ViewModel
    {
        public ObservableCollection<CheckComboBoxItems> CheckComboBoxItems { get; set; } = new ObservableCollection<CheckComboBoxItems>();
    }

    public class CheckComboBoxItems : INotifyPropertyChanged
    {
        private bool _isChecked;
        private string _item;

        public bool IsChecked
        {
            get
            {
                return _isChecked;
            }
            set
            {
                _isChecked = value;
                NotifyPropertyChanged("IsChecked");
            }
        }


        public string Item
        {
            get
            {
                return _item;
            }
            set
            {
                _item = value;
                NotifyPropertyChanged("Item");
            }
        }

        private void NotifyPropertyChanged(string propertyName)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }

        public event PropertyChangedEventHandler PropertyChanged;
    }
}

MainWindow.xaml

<Window x:Class="WpfApp6.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WpfApp6"
         xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">
    <StackPanel>
        <xctk:CheckComboBox ItemsSource="{Binding CheckComboBoxItems}" DisplayMemberPath="Item" SelectedMemberPath="IsChecked" Height="50" Width="150"/>
        <Button Content="Set A und C" Width="150" Height="50" Margin="20" Click="Button_Click"/>
    </StackPanel>
</Window>
PythonNoob
  • 914
  • 1
  • 7
  • 15
-1

From the documentation, it doesn't look like there is a way to make the combo box bind the check box state to an item property. Rather, the selected items are exposed via the SelectedItems property. You can specify your own collection to hold the selected items with SelectedItemsOverride, so binding it to IsFiltered doesn't make sense. What you'll probably have to do is bind SelectedItemsOverride to an ObservableCollection<NapTypeItem> and manually observe changes to the collection, and update the items' IsFiltered property when the selection changes.

Mike Strobel
  • 25,075
  • 57
  • 69