November 2009 - Posts

Getting SelectedValue from Wpf Combobox

Hi, i don't know why this seemed not easy but here is how it goes

Your XAML for the WPF Combo

<ComboBox Name="ddlApplication" DisplayMemberPath="AppName" SelectedValuePath="ID"  SelectedItem="App" Margin="92.709,56,220.46,0" VerticalAlignment="Top" Height="22.96" SelectionChanged="ddlApplication_SelectionChanged" />

Then you can easily bind a IList<YourObject> like this

  ddlApplication.ItemsSource = list;

            if (ddlApplication.HasItems)

            {

                ddlApplication.SelectedIndex = 0;

            }

and getting the selected value is easy as

 YourObject obj =  (YourObject)ddlApplication.SelectedItem;

            this.Title = obj .ID.ToString();

Done!  happy xamiling 

Posted by Adel Khalil with 2 comment(s)
Filed under: , ,