using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; namespace WpfDatabind5 { /// /// Interaction logic for MainWindow.xaml /// public partial class MainWindow : Window { public bool filter =false; public MainWindow() { InitializeComponent(); this.Background = Brushes.Azure; grid1.Background = Brushes.Beige; Class1[] _class1 = { new Class1("Mary", 27, "Tech"), new Class1("Joe", 34, "Manager"), new Class1("Jim", 29, "Clerk"), new Class1("Anida", 34, "CS")}; // grid1.DataContext = _class1; grid1.DataContext = _class1; Binding bindName = new Binding("ename"); lblName.SetBinding(ContentProperty, bindName); Binding bindAge = new Binding("age"); lblAge.SetBinding(ContentProperty, bindAge); Binding bindPos = new Binding("position"); lblPos.SetBinding(ContentProperty, bindPos); // comboBox1.DisplayMemberPath = "ename"; comboBox1.ItemsSource = _class1; comboBox1.SelectedIndex =-1; comboBox1.IsSynchronizedWithCurrentItem = true; // comboBox2.SelectedIndex = 0; comboBox2.ItemsSource = LoadComboBoxData(); } private string[] LoadComboBoxData() { string[] strArray = { "Jan", "Feb", "Mar", "Apr", "May", "June", "July" }; return strArray; } private void comboBox1_SelectionChanged(object sender, SelectionChangedEventArgs e) { label4.Background = Brushes.BlanchedAlmond; label5.Background = Brushes.BlanchedAlmond; label4.Content= comboBox1.SelectedItem.ToString(); label5.Content = comboBox1.SelectedIndex; } private void comboBox2_SelectionChanged(object sender, SelectionChangedEventArgs e) { label4.Background = Brushes.Goldenrod; label5.Background = Brushes.Fuchsia; label4.Content = comboBox2.SelectedItem.ToString(); label5.Content = "Index " + comboBox2.SelectedIndex + " Text "+ comboBox2.Text; } } }