Click here to Skip to main content
15,882,241 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

i have list of all color in combo box

<combobox height="23" margin="11,66,11,0" name="comboBox1" verticalalignment="Top" displaymemberpath="Title" selectionchanged="comboBox1_SelectionChanged" selectedindex="0"></combobox>

And i have 1 ellipse

 <ellipse verticalalignment="Center" horizontalalignment="Center" width="280" height="280"> Fill="" StrokeThickness="3" Opacity="22" OpacityMask="Blue"/>


i want when to change the color of ellipse .. by selecting color from combo box...

How i can bind this property...
Plse Help Me...
Updated 31-Jul-17 3:37am

You can set a name for the ellipse and set it in code, or you can do a binding to the selected color in the combobox. Both ways you need to set a name (x:Name=) to the combobox.
Share this answer
dilip.aim11 5-Aug-11 3:14am    
i am able to change background color of button...
using brush property from code window...

but i not able to find my ellipse in code window... i give the name of a=ellipse but it not come in code window....
UJimbo 5-Aug-11 3:46am    
Modify your Ellipse with x:Name="a_ellipse", and you should be able to find it
You need a SolidColorBrush[^] if you want to change the fill color of your ellipse. Set the necessary property of your SolidColorBrush object and then assign it to the Fill property of your ellipse. Of course you need to set some condition on which color to set on your SolidColorBrush object when a value is selected on your combobox. This[^] could probably help.
Share this answer
Basic idea is: populate your combo box with all brushes you need. For list item content, use members of System.Windows.Media.Brushes, see[^]. In the handler of the event of ComboBox.SelectionChanged, type-cast the content of the combo box element to SolidColorBrush and assign it to the property Fill of the Ellipse.

For a combo box item, you can use as complex content as you want; it is only important that you have object of the type SolidColorBrush or Brush at some level of nesting. In this way, you can show color and, for example, its name in the combo box list item.

Here is a very simple example:

      <TextBlock Background="Red">Red</TextBlock>  
      <TextBlock Background="Yellow">Yellow</TextBlock>
      <TextBlock Background="AliceBlue">Alice Blue</TextBlock>

It's not perfect, just gives you the idea what can you have for a control (combo box) used for color selection.

All trick is in the design of a ComboBoxItem content and using it. So, read this:[^].

Another different level of WPF "custom drawing" is styling and templating. Read[^].

Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900