多选组合框瓦特/标志枚举 [英] Multiselect Combobox w/ Flags Enum

查看:117
本文介绍了多选组合框瓦特/标志枚举的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望有人能帮助我了这一点。我以前也问过类似的问题,但我并没有有任何东西的时候就这样开始了。我已经找到了SO问题链接

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 link

这是类似于我的问题,但它有一个问题。组合框不显示选定的枚举。我做的例子,在我的示例应用程序工作的链接,但我不知道如何获得组合框的文字显示当前选中的项目(S)。任何人有做什么建议?我是真正的停留在这一个。

that is similar to my problem but it has one issue. The combobox doesn't show the selected enums. I do the example in the link working in my sample app but I have no clue how to get the Combobox's text to show the currently selected item(s). Anyone have a suggestion on what to do? I am real stuck on this one.

下面是我当前的ComboBox:

Here is my current combobox:

<ComboBox>
    <CheckBox Content="SAW" IsChecked="{Binding Path=CurWeldingProcess, Converter={StaticResource wpFlagValueConverter}, ConverterParameter={x:Static models:WeldingProcess.SAW}}" />
    <CheckBox Content="FCAW" IsChecked="{Binding Path=CurWeldingProcess, Converter={StaticResource wpFlagValueConverter}, ConverterParameter={x:Static models:WeldingProcess.FCAW}}" />
    <CheckBox Content="SMAW" IsChecked="{Binding Path=CurWeldingProcess, Converter={StaticResource wpFlagValueConverter}, ConverterParameter={x:Static models:WeldingProcess.SMAW}}" />
</ComboBox>



我的转换是:

My Converter is:

public class WeldingProcessFlagValueConverter : IValueConverter
{
    private WeldingProcess target;

    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        WeldingProcess mask = (WeldingProcess)parameter;
        this.target = (WeldingProcess)value;
        return ((mask & this.target) != 0);
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        this.target ^= (WeldingProcess)parameter;
        return this.target;
    }
}



所以我的'CurWeldingProcess显示的是正确的值时,我选择复选框的任意组合,但我不知道怎么去组合框来显示选定的值('CurWeldingProcess')。任何想法?

So my 'CurWeldingProcess' is showing the correct value when I select any combination of the checkboxes, but I dont know how to get the combobox to show the selected values ('CurWeldingProcess'). Any ideas?

推荐答案

如果你需要显示所选项目的串联(即,如果我检查SAW和SMAW枚举价值观,我想在组合框的文本类似于SAW,SMAW)看看,你可以看看这个的多选组合框在WPF

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.

您将找到一个MVVM版和代码隐藏之一。

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

修改

好吧,你可以去的 CodeProject上并下载MultiSelectComboBox DLL。添加在您的项目。
然后在你的XAML可以添加:

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

<Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:multi="clr-namespace:MultiSelectComboBox;assembly=MultiSelectComboBox"
        Title="MainWindow" Height="350" Width="600">
    <!-- your xaml -->
        <multi:MultiSelectComboBox Margin="4" Name="MultiSelectComboBox" />
    <!-- the rest of your xaml -->
</Window>



然后在你的代码隐藏(我用我的样本 TextAlignment 枚举):

public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();

        Dictionary<string, object> itemsSource = new Dictionary<string, object>();
        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;
    }
}



SelectedItems 的MultiSelectComboBox的属性将包含用户选择的值。
是它,你需要什么?
如果你正在使用MVVM可以揭露的ItemsSource和你的ViewModel的SelectedItems字典。

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.

这篇关于多选组合框瓦特/标志枚举的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆