admin 管理员组文章数量: 1184232
My markup does not want to change the background of neither the ComboBox nor for the selected ComboBoxItem. It additionally does not change the hover color of ComboBoxItems. How does this make sense? Also if possible, I'd also like to know how to remove the scroll bar in the list with the items, since I couldn't find anything about it.
Preview of Issue
<UserControl.Resources>
<Style TargetType="{x:Type ComboBox}">
<Setter Property="Background" Value="{DynamicResource PanelBackground}" />
<Setter Property="Foreground" Value="{DynamicResource TextColor}" />
<Setter Property="BorderBrush" Value="{DynamicResource BorderBrush}" />
</Style>
<Style TargetType="{x:Type ComboBoxItem}">
<Setter Property="Background" Value="{DynamicResource PanelBackground}" />
<Setter Property="Foreground" Value="{DynamicResource TextColor}" />
<Setter Property="BorderBrush" Value="{DynamicResource BorderBrush}" />
<Setter Property="Padding" Value="4,2" />
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="{DynamicResource HoverColor}" />
</Trigger>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="{DynamicResource PanelBackground}" />
<Setter Property="Foreground" Value="{DynamicResource TextColor}" />
</Trigger>
</Style.Triggers>
</Style>
I've tried with and without control templates and I have even played around with properties of different values and other, seemingly unrelated, properties. I'm using a control template for the hover color on a button, but either I wrote the markup incorrectly or it doesn't work with ComboBoxes.
My markup does not want to change the background of neither the ComboBox nor for the selected ComboBoxItem. It additionally does not change the hover color of ComboBoxItems. How does this make sense? Also if possible, I'd also like to know how to remove the scroll bar in the list with the items, since I couldn't find anything about it.
Preview of Issue
<UserControl.Resources>
<Style TargetType="{x:Type ComboBox}">
<Setter Property="Background" Value="{DynamicResource PanelBackground}" />
<Setter Property="Foreground" Value="{DynamicResource TextColor}" />
<Setter Property="BorderBrush" Value="{DynamicResource BorderBrush}" />
</Style>
<Style TargetType="{x:Type ComboBoxItem}">
<Setter Property="Background" Value="{DynamicResource PanelBackground}" />
<Setter Property="Foreground" Value="{DynamicResource TextColor}" />
<Setter Property="BorderBrush" Value="{DynamicResource BorderBrush}" />
<Setter Property="Padding" Value="4,2" />
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="{DynamicResource HoverColor}" />
</Trigger>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="{DynamicResource PanelBackground}" />
<Setter Property="Foreground" Value="{DynamicResource TextColor}" />
</Trigger>
</Style.Triggers>
</Style>
I've tried with and without control templates and I have even played around with properties of different values and other, seemingly unrelated, properties. I'm using a control template for the hover color on a button, but either I wrote the markup incorrectly or it doesn't work with ComboBoxes.
Share Improve this question edited Feb 12 at 10:31 ASh 35.7k9 gold badges65 silver badges87 bronze badges asked Feb 12 at 10:16 wildREAwildREA 11 bronze badge 3 |1 Answer
Reset to default 0for your usecase it seems like you have to generate a custom control template.
For reference here someone already tried to create a custom combobox. custom combobox in wpf Application
If you'd like to use the original design, you can find the source here: https://learn.microsoft/en-us/dotnet/desktop/wpf/controls/combobox-styles-and-templates?view=netframeworkdesktop-4.8#combobox-controltemplate-example
Hope I was able to help you with those sources for now
PS: in the complete template you also find a setter for the ScrollBarVisibility, which value is in default Auto
本文标签:
版权声明:本文标题:.net - XAML ComboBox Styling Not Applying: Background, Selection, and Hover Issues - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.roclinux.cn/p/1741608015a2305384.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
ComboBoxcontrol. Note that control template is not the only solution; I would prefer a custom control. – Sergey A Kryukov Commented Feb 12 at 21:55ComboBox. You create a new classpublic class ComboBox : System.Windows.Controls.Primitives.Selector, and so on. Basically, from scratch. Inside the control, use elements for text, list, and button(s). Define your behavior. Define all dependency properties you may need for the new flexibility. Reuse in different projects. – Sergey A Kryukov Commented Feb 13 at 14:27