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????
Solved! Go to Solution.
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.
try on this ,
lineSymbole.Color = new SolidColorBrush((Color)BorderBrushCmbo.SelectedItem) as SolidColorBrush;
thank you for replying Asghar khan
i try it but it give me these error message
"Specified cast is not valid."
an help please this is urgent
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.
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
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
this is my email