WPF Combo box - Select Item by Tag
Looks like you're looking for the proeprty SelectedValuePath of ComboBox control. See example here http://msdn.microsoft.com/en-us/library/system.windows.controls.primitives.selector.selectedvaluepath.aspx
For those people who cannot find example under the link above and keep downvoting I prepared my own example. It highlights how to setup ComboBox and select appropriate item by assigning selected value.
MainWindow.xaml
<Window x:Class="WpfApp1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" Height="97" Width="202">
<Window.Resources>
<XmlDataProvider x:Key="Questions" XPath="/Questions/*">
<x:XData>
<Questions xmlns="">
<Question Title="Question 1" Index="1" />
<Question Title="Question 2" Index="2" />
<Question Title="Question 3" Index="3" />
<Question Title="Question 4" Index="4" />
</Questions>
</x:XData>
</XmlDataProvider>
<DataTemplate x:Key="QuestionItemTemplate">
<TextBlock Text="{Binding XPath=@Title}" />
</DataTemplate>
</Window.Resources>
<StackPanel>
<ComboBox Name="myMenu"
ItemsSource="{Binding Source={StaticResource Questions}}"
ItemTemplate="{StaticResource QuestionItemTemplate}"
SelectedValuePath="@Index"/>
<TextBlock Text="{Binding ElementName=myMenu,
Path=SelectedValue, StringFormat=Selected Index: {0:D}}"/>
<Button Content="Select another item" Click="Button_Click" />
</StackPanel>
MainWindow.xaml.cs
using System.Windows;
namespace WpfApp1
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
myMenu.SelectedValue = ++_counter;
if (_counter > 3) _counter = 0;
}
private int _counter = 0;
}
}