红色轮廓显示在C#wpf中的Combobox上

时间:2014-08-16 09:47:15

标签: c# wpf xaml combobox

我有一个Wpf应用程序它有一个Combobox。 当我点击复选框时,它包含一个复选框和Textblock 它显示组合框中选定的国家/地区字符串,但如果我单击文本,它会显示错误字符串,如图所示。 即使用户点击了文本块,我也希望显示国家/地区名称。

enter image description here

我的xaml看起来像这样

                <ComboBox   Text="{Binding CurrentCountries}"  ToolTip="{Binding CurrentCountries}" Grid.Column="0" Grid.Row="0" HorizontalAlignment="Left"  Name="cmbCountry" IsEditable="True" IsReadOnly="True"  TextSearch.TextPath="{Binding CountryName}"  HorizontalContentAlignment="Left" Margin="80,14,0,0" VerticalAlignment="Top" Width="100 " ItemsSource="{Binding Country, Mode=TwoWay}"  SelectedItem="{Binding SelectedCountry,Mode= TwoWay}" Height="22" TabIndex="1">

                    <ComboBox.ItemTemplate>

                        <DataTemplate>
                            <CheckBox Name="Country"  HorizontalAlignment="Left" Grid.Column="0"   Content="{Binding CountryName}" IsChecked="{Binding IsChecked}">
                                <i:Interaction.Triggers>
                                    <i:EventTrigger EventName="Checked">
                                        <Commands:EventToCommand Command="{Binding DataContext.CountryCheckedCmd,RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type telerik:RadWindow}}}" CommandParameter="{Binding ElementName=Country}" ></Commands:EventToCommand>
                                    </i:EventTrigger>
                                    <i:EventTrigger EventName="Unchecked">
                                        <Commands:EventToCommand Command="{Binding DataContext.CountryUnCheckedCmd,RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type telerik:RadWindow}}}" CommandParameter="{Binding ElementName=Country}" ></Commands:EventToCommand>
                                    </i:EventTrigger>
                                </i:Interaction.Triggers>
                            </CheckBox>
                        </DataTemplate>
                    </ComboBox.ItemTemplate>
                </ComboBox>
谢谢你!

1 个答案:

答案 0 :(得分:0)

如果你想要多选ComboBox,你应该使用CheckComboBox中的WPF Extended Toolkit

使用起来非常简单,例如:

<xctk:CheckComboBox x:Name="_combo" 
                   HorizontalAlignment="Center" 
                   VerticalAlignment="Center" 
                   DisplayMemberPath="Color"
                   ValueMemberPath="Level"
                   SelectedValue="{Binding SelectedValue}"
                   SelectedItems="{Binding SelectedItems}" />