简体   繁体   中英

Multi selection ComboBox ,WPF

i want my comboBox to contain radio buttons as it's comboBoxItems for multiselection. the Xaml for that is :

<ComboBox Background="Transparent" x:FieldModifier="public" Margin="0,0,0,0" x:Name="comboBox_Errors" FontSize="11"  MinHeight="19" Height="Auto" MinWidth="150" BorderThickness="1">
                                <ComboBox.ItemTemplate>
                                    <HierarchicalDataTemplate>
                                        <RadioButton />
                                    </HierarchicalDataTemplate>
                                </ComboBox.ItemTemplate>
                            </ComboBox>

and this the code for trying this comboBox:

            ComboBoxItem c1 = new ComboBoxItem();
            c1.Content = "Error 1";
            this.DataControl_PalcesDataControl.comboBox_Errors.Items.Add(c1);
            ComboBoxItem c2 = new ComboBoxItem();
            c2.Content = "Error 2";
            this.DataControl_PalcesDataControl.comboBox_Errors.Items.Add(c2);
            ComboBoxItem c3 = new ComboBoxItem();
            c3.Content = "Error 3";
            this.DataControl_PalcesDataControl.comboBox_Errors.Items.Add(c3);
            ComboBoxItem c4 = new ComboBoxItem();
            c4.Content = "Error 4";
            this.DataControl_PalcesDataControl.comboBox_Errors.Items.Add(c4);
            ComboBoxItem c5 = new ComboBoxItem();
            c5.Content = "Error 5";
            this.DataControl_PalcesDataControl.comboBox_Errors.Items.Add(c5);

when i run the application , there is nothing in the comboBox...what is the problem? than you.

There is no need to create ComboBoxItem, just add the strings to the comboBox_Errors:

comboBox_Errors.Items.Add("Error 1");

Also, you need to ask the RadioButton to show something, the easiest way would probably be to do:

<RadioButton Content="{Binding}" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM