gpt4 book ai didi

c# - WPF 组合框 : Align selected value and/or drop down items

转载 作者:行者123 更新时间:2023-12-05 08:57:14 25 4
gpt4 key购买 nike

我有一个几乎默认的 WPF ComboBox:

enter image description here

什么是最简单的对齐项目的方法,例如,在组合框的输入和/或下拉列表中向右

我环顾四周,只发现了与控件模板混淆的解决方案,在我看来,对于这样一个简单的事情来说,这太遥远了。我不敢相信没有更简单的解决方案可以用来对齐项目。

更新:由于 dkozl 的回答,我已经稍微重新表述了这个问题,以涵盖更广泛的案例集,进一步的读者可能会体验到这个主题。

此外,它应该防止某些人试图将此问题作为重复问题关闭。

最佳答案

如果您想要右对齐所选值和下拉项,那么针对 ComboBox 设置 Horizo​​ntalContentAlignment="Right" 就足够了

<ComboBox ... HorizontalContentAlignment="Right">

如果您想右对齐仅下拉项,那么您需要更改ComboBoxItemHorizo​​ntalContentAlignment

<ComboBox>
<ComboBox.ItemContainerStyle>
<Style TargetType="{x:Type ComboBoxItem}">
<Setter Property="HorizontalContentAlignment" Value="Right"/>
</Style>
</ComboBox.ItemContainerStyle>
</ComboBox>

并向右对齐仅选择的值两者的组合

<ComboBox ... HorizontalContentAlignment="Right">
<ComboBox.ItemContainerStyle>
<Style TargetType="{x:Type ComboBoxItem}">
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
</Style>
</ComboBox.ItemContainerStyle>
</ComboBox>

关于c# - WPF 组合框 : Align selected value and/or drop down items,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34684757/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com