Multiselect Combobox w/ Flags Enum

后端 未结 1 1576
一生所求
一生所求 2021-01-17 02:59

I am hoping someone can help me out with this. I have asked a similar question before but I didn\'t have anything started on this at the time. I have found the SO question l

1条回答
  •  长发绾君心
    2021-01-17 03:33

    If you need to show a "concatenation" of the selected items (i.e. if I check SAW and SMAW enum values, I would like to see in the ComboBox Text something like "SAW, SMAW"), you can take a look to this Multi Select ComboBox in WPF.

    You will find both a MVVM version and "codebehind" one.

    EDIT

    Ok, you can go the CodeProject and download the MultiSelectComboBox dll. Add it in your project. Then in your XAML you can add:

    
        
            
        
    
    

    Then in your code-behind (I used for my sample the TextAlignment enum):

    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
    
            Dictionary itemsSource = new Dictionary();
            itemsSource.Add(Convert.ToString(TextAlignment.Center), TextAlignment.Center);
            itemsSource.Add(Convert.ToString(TextAlignment.Justify), TextAlignment.Justify);
            itemsSource.Add(Convert.ToString(TextAlignment.Left), TextAlignment.Left);
            itemsSource.Add(Convert.ToString(TextAlignment.Right), TextAlignment.Right);
    
            MultiSelectComboBox.ItemsSource = itemsSource;
        }
    }
    

    The SelectedItems property of the MultiSelectComboBox will contain the values that the user selected. Is it what you needed? If you are using MVVM you can expose the ItemsSource and the SelectedItems dictionaries with your ViewModel.

    0 讨论(0)
提交回复
热议问题