I have the following XAML:
<ComboBox Height="23" HorizontalAlignment="Left" Grid.Row="6" Grid.Column="2"
Name="cbo_team" VerticalAlignment="Top" Width="148"
DataContext="{Binding ElementName=cbo_component, Path=SelectedItem}"
SelectedIndex="0">
<ComboBox.ItemsSource>
<Binding XPath="Teams/Team/@id"
Converter="{StaticResource xmlConverter}">
<Binding.ConverterParameter>
<local:XmlConverterParameter
XPathTemplate="/Products/Teams/Team[{0}]"
XPathCondition="@id='{0}'" />
</Binding.ConverterParameter>
</Binding>
</ComboBox.ItemsSource>
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding XPath=@name}" />
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
In C#, I'm trying to get the value of the TextBlock that is in the current selected item in the ComboBox. How do I do that? This question is pretty much the same, but the only answer doesn't help.
private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
var comboBox = (ComboBox)sender;
ComboBoxItem comboAsTextblock = (ComboBoxItem)comboBox.SelectedItem;
string comboBoxItemText = comboAsTextblock.Content.ToString();
// comboBoxItemText is what you want :)
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With