当ComboBox在DataGridComboBoxColumn中时,可以通过自定义样式来隐藏组合框的下拉列表。具体步骤如下:
<Window.Resources>
<Style x:Key="ComboBoxStyle" TargetType="ComboBox">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ComboBox">
<Grid>
<ToggleButton x:Name="ToggleButton" ClickMode="Press" Focusable="False" IsChecked="{Binding Path=IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" />
<ContentPresenter x:Name="ContentPresenter" ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}" Content="{TemplateBinding SelectionBoxItem}" ContentStringFormat="{TemplateBinding SelectionBoxItemStringFormat}" HorizontalAlignment="Left" Margin="3,3,23,3" VerticalAlignment="Center" />
<TextBox x:Name="PART_EditableTextBox" Background="Transparent" Focusable="False" HorizontalAlignment="Left" IsReadOnly="True" IsEnabled="{TemplateBinding IsEnabled}" Margin="3,3,23,3" Style="{x:Null}" VerticalAlignment="Center" />
<Popup x:Name="Popup" Focusable="False" IsOpen="{TemplateBinding IsDropDownOpen}" Placement="Bottom" PopupAnimation="Slide">
<Grid x:Name="DropDown" Background="White" SnapsToDevicePixels="True">
<ScrollViewer>
<ItemsPresenter />
</ScrollViewer>
</Grid>
</Popup>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
<DataGridComboBoxColumn Header="ComboBox Column" SelectedItemBinding="{Binding ComboBoxProperty}" >
<DataGridComboBoxColumn.ElementStyle>
<Style TargetType="ComboBox">
<Setter Property="Style" Value="{StaticResource ComboBoxStyle}" />
</Style>
</DataGridComboBoxColumn.ElementStyle>
<DataGridComboBoxColumn.EditingElementStyle>
<Style TargetType="ComboBox">
<Setter Property="Style" Value="{StaticResource ComboBoxStyle}" />
</Style>
</DataGridComboBoxColumn.EditingElementStyle>
</DataGridComboBoxColumn>
通过以上步骤,ComboBox在DataGridComboBoxColumn中的下拉列表将被隐藏,只显示当前选中的项。
领取专属 10元无门槛券
手把手带您无忧上云