[英]wpf ComboBox Selected Item Displaying different text then item in drop down
[英]WPF ComboBox: Align selected value and/or drop down items
如果要同時右對齊選定的值和下拉菜單項,那么對ComboBox
設置HorizontalContentAlignment="Right"
就足夠了
<ComboBox ... HorizontalContentAlignment="Right">
如果只想使下拉項右對齊,則需要更改ComboBoxItem
HorizontalContentAlignment
<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>
我已經嘗試了dkozl的答案,並且出於某種原因,對我的ComboBox
設置HorizontalContentAlignment
足以使combobox的輸入和下拉菜單中的正確項對齊。
我遇到了在右側對齊所選項目的問題,以便用戶始終可以看到字符串的結尾。 我發現的最簡單的解決方案如下
<ComboBox ...>
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock HorizontalAlignment="Right" Text="{Binding textProp}" />
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.