在组合框中禁用下拉菜单的选择 [英] Disable selection of drop down items in ComboBox
问题描述
我有一个comboBox,其样式设置为具有文本行和复选框,以允许用户检查不同内容的列表。我想做的是禁用组合框中的行选择。
I have a comboBox that is styled to have rows of text blocks and check boxes to allow user to check a list of different things. What I am attempting to do is disable selection of a row in the the 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>
这是我的下拉菜单的图片:
这是我不喜欢的图片想要:
< img src = https://i.stack.imgur.com/vnAN7.png alt =在此处输入图片描述>
我要禁用用户选择特定行的功能,但保留用户在下拉菜单中选择各种复选框的功能。有样式的方法吗?
I want to disable the ability for the user to select a specific row, but keep the ability for them to select various check boxes in the drop down. Is there a way to style this?
推荐答案
我遇到了同样的问题,我通过使用 ToggleButton
与 Popup
组合(而不是使用 ComboBox
)
I had the same issue, i solved it by using a ToggleButton
in combination with a Popup
(instead of using a 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>
这篇关于在组合框中禁用下拉菜单的选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!