[英]How to keep the background color of the selected item of a Combobox in WPF after setting its text?
我在WPF
中有一個ComboBox
並且我通過Edit Template -> Edit a Copy
並且工作正常。 在此之后,我使用IsReadOnly="True" IsEditable="True" Text="Some Text"
設置其默認文本。 當您單擊下拉菜單時,將此文本添加到 combobox 將其背景顏色覆蓋為白色,而不是項目的背景顏色。 知道如何解決這個問題嗎?
您可以通過定義ItemContainerStyle
來更改項目的背景顏色:
<ComboBox ...>
<ComboBox.ItemContainerStyle>
<Style TargetType="ComboBoxItem">
<Setter Property="Background" Value="LightBlue" />
</Style>
</ComboBox.ItemContainerStyle>
</ComboBox>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.