簡體   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