Skip to main content
Home Forums General Silverlight Getting Started How to set background color for ComboBox?
3 replies. Latest Post by kent.zhou on January 5, 2009.
(0)
kent.zhou
Member
109 points
397 Posts
12-30-2008 3:57 PM |
How to set background color only for dropdown list box for ComboBox not for the text field? I tried to set Property Background and it seemed ineffective.
vitor_ca...
152 points
41 Posts
12-30-2008 5:45 PM |
I dont't know exacly you need. If you show me a image with your wish. But if I need to change the appearance of a control I open with Expression Blend 2 and select him. After that I do a reverse click on control in "Objects and Timeline", "Edit Control Parts (Template)", "Edit a Copy" and select to do this in application. Like this:
Amanda W...
All-Star
17241 points
1,466 Posts
01-05-2009 2:33 AM |
Hi Kent,
If you want the dropdown list has the different background color with the text field, you can set the ComboBoxItem's Background, below code work fine on our labs:
<ComboBox Height="40" Margin="49,43,150,0" VerticalAlignment="Top" Background="#FF0F51EB"> <ComboBoxItem Content="Item1" Background="#FFEC1313"/> <ComboBoxItem Content="Item1" Background="#FF24E643"/> <ComboBoxItem Content="Item1" Background="#FF8B2CE4"/> </ComboBox>
01-05-2009 10:34 AM |
Thanks for your information. My ComboBox uses template for the list item. It looks like:
<ComboBox x:Name="xMyList" Height="20" Style="{StaticResource FormComboBox}"> <ComboBox.ItemTemplate> <DataTemplate> <StackPanel Orientation="Horizontal"> <TextBlock Width="150" Text="{Binding Path=myName}" VerticalAlignment="Center" FontSize="10" /> </StackPanel> </DataTemplate> </ComboBox.ItemTemplate></ComboBox>
For template there is no backgroupd property. I can set background for Stackpanel, but that only be effective for the list item, between the item in the list , there is a gap with another color. What I want is set the a background color for whole box for the dropdown(Default is white), not each item in the list.