繁体   English   中英

在组合框中禁用下拉菜单的选择

[英]Disable selection of drop down items in ComboBox

我有一个comboBox,其样式设置为具有文本块和复选框行,以允许用户检查不同事物的列表。 我正在尝试做的是禁用组合框中的一行选择。

我的查看代码:

<ComboBox ItemsSource="{Binding HeaderList}" 
    IsSelected="False"
    HorizontalAlignment="Left"
    Height="10"
    x:Name="ComboBox">
    <ComboBox.ItemTemplate>
       <DataTemplate>
          <StackPanel Orientation="Horizontal">
             <CheckBox IsChecked="{Binding IsChecked}"/>
             <TextBlock Text="{Binding HeaderName}"/>
          </StackPanel>
       </DataTemplate>
    </ComboBox.ItemTemplate>
</ComboBox>

这是我的下拉菜单的图片:

在此处输入图片说明

这是我不想要的照片:

在此处输入图片说明

我想禁用用户选择特定行的功能,但保留他们在下拉列表中选择各种复选框的功能。 有样式的方法吗?

我有同样的问题,我通过结合使用ToggleButtonPopup (而不是使用ComboBox )来解决了

注意:未经测试

<ToggleButton x:Name="filterButton" />
<Popup x:Name="popup" 
    AllowsTransparency="True" 
    StaysOpen="False"
    PlacementTarget="{Binding ElementName=filterButton}"
    IsOpen="{Binding ElementName=filterButton,Path=IsChecked,Mode=TwoWay}">
    <ItemsControl ItemsSource="{Binding HeaderList}">
        <ItemsControl.ItemTemplate>
            <DataTemplate>
                <StackPanel Orientation="Horizontal">
                    <CheckBox IsChecked="{Binding IsChecked}"/>
                    <TextBlock Text="{Binding HeaderName}"/>
                </StackPanel>
            </DataTemplate>                                    
        </ItemsControl.ItemTemplate>
    </ItemsControl>
</Popup>

您可以尝试在selectionchanged事件中将组合框的selectedindex设置为-1

private void myComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        myComboBox.SelectedIndex = -1;
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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