MainWindow.xaml.cs:
public partial class MainWindow : Window { private List<String> list = new List<string>(); public List<String> List { get { return this.list; } set { this.list = value; } } public MainWindow() { InitializeComponent(); list.Add("methode"); list.Add("methode"); list.Add("methode"); list.Add("methode2"); list.Add("methode2"); this.DataContext = this; } private void comboBox1_SelectionChanged(object sender, SelectionChangedEventArgs e) { MessageBox.Show(comboBox1.SelectedIndex.ToString()); } }
MainWindow.xaml:
<Window x:Class="Temp2.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525"> <Grid> <ComboBox Height="23" HorizontalAlignment="Left" Name="comboBox1" VerticalAlignment="Top" Width="120" SelectionChanged="comboBox1_SelectionChanged" ItemsSource="{Binding List}" /> </Grid> </Window>
works great for me. Can you clarify your question? Keep in mind that I tried different types and always got a working result.
source share