Select to view content in your preferred language

Color Picker Combo Box

5480
7
Jump to solution
03-17-2015 04:17 AM
yousofothman
Deactivated User

hi every body

i  use these color picker ComboBox:

<ComboBox x:Name="BorderBrushCmbo" FlowDirection="RightToLeft" ItemsSource="{Binding Colors}" SelectedItem="{Binding Color, Mode=TwoWay}" Width="140" Height="24">
                        <ComboBox.ItemTemplate>
                            <DataTemplate>
                                <Canvas Background="{Binding ., Converter={StaticResource StringToBrushConverter}}" Width="100" Height="18">
                                </Canvas>
                            </DataTemplate>
                        </ComboBox.ItemTemplate>
                    </ComboBox>

to display colors for users

it work very well but i could not read the value of selected color of ComboBox to display it on the symbol fore drawing graphic on the map

my question is how to read the value of selected color from color picker ComboBox

i try to do these:

 lineSymbole.Color = new SolidColorBrush((Color)BorderBrushCmbo.SelectedItem);

then i try also these:

Color c = (Color)Convert.ChangeType(BorderBrushCmbo.SelectedItem.ToString(), typeof(Color),null);
lineSymbole.Color = new SolidColorBrush(c);

but I face a problem that i can not convert system color to solid color brush

any help please????

0 Kudos
1 Solution

Accepted Solutions
DominiqueBroux
Esri Frequent Contributor

Difficult to answer to this question without knowing how is defined your 'Colors' property which is binded to the ItemsSource.

Very likely it's just a string collection so 'SelectedItem' is a string and you eventually have to convert a string to a Brush.

It's likely what you are already doing in your 'StringToBrushConverter' so the same kind of code should work.

View solution in original post

7 Replies
Asgharkhan
Regular Contributor

try on this ,

lineSymbole.Color = new SolidColorBrush((Color)BorderBrushCmbo.SelectedItem) as SolidColorBrush;

0 Kudos
yousofothman
Deactivated User

thank you for replying Asghar khan

i try it but it give me these error message

"Specified cast is not valid."

0 Kudos
yousofothman
Deactivated User

an help please this is urgent

0 Kudos
DominiqueBroux
Esri Frequent Contributor

Difficult to answer to this question without knowing how is defined your 'Colors' property which is binded to the ItemsSource.

Very likely it's just a string collection so 'SelectedItem' is a string and you eventually have to convert a string to a Brush.

It's likely what you are already doing in your 'StringToBrushConverter' so the same kind of code should work.

yousofothman
Deactivated User

thank you very much

i return back the StringToBrushConverter file

and i try these

string colorString = BorderBrushCmbo1.SelectionBoxItem.ToString();
                    Color c = new Color();
                c.A = 255;
                c.R = byte.Parse(colorString.Substring(0, 2), NumberStyles.HexNumber);
                c.G = byte.Parse(colorString.Substring(2, 2), NumberStyles.HexNumber);
                c.B = byte.Parse(colorString.Substring(4, 2), NumberStyles.HexNumber);
                  
                        lineSymbole.Color = new SolidColorBrush(c);

it work for me

thank you very much

0 Kudos
Asgharkhan
Regular Contributor

This is possible in one condition if u define dependency.

@yousof othman i have a sample in wpf,  i well send u tommorow.

Today i was sick and not go to office...

Please provide me  your email

0 Kudos
yousofothman
Deactivated User

this is my email

yousofmakkawy@yahoo.com

0 Kudos