Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

access Single Element in multiTemplate ComboBox Item

$
0
0

hello all

i have project To Formatting RichTextBox Text 

and have ComboBox that Display colors as [Color it self : Color Name ]

:

<ComboBox Name="cboColors" Width="80" IsTextSearchEnabled="True"
                              ItemsSource="{Binding Source={StaticResource colorPropertiesOdp}}"
                              SelectedValuePath="Name" SelectionChanged="cboColors_SelectionChanged"><ComboBox.ItemTemplate><DataTemplate><StackPanel Orientation="Horizontal" Height="18" Margin="0,0,0,2"><Border BorderThickness="1" CornerRadius="2" 
                                            BorderBrush="Black" Width="50" VerticalAlignment="Stretch"
                                            Background="{Binding Name}"/><TextBlock Text="{Binding Name}" Margin="8,0,0,0"/></StackPanel></DataTemplate></ComboBox.ItemTemplate></ComboBox>

i want when user Select Color from this combo to apply it to RichTextBox 

Like :

txtMessage.Foreground = new SolidColorBrush( (Color)cboColors.SelectedItem);

but i get error :

//Specified cast is not valid.


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>