I want to convert a small win-form app to WPF App.
I am using linq-sql and below is the dbml file
This is my xaml code file in which I have 1 combobox and other textboxes
<ComboBox Height="23" IsDropDownOpen="False" Margin="107,52,281,0" Name="cbx_contact" VerticalAlignment="Top" />
<Label Height="17" HorizontalAlignment="Left" Margin="25,55,0,0" VerticalAlignment="Top" Width="72">Contact :</Label>
<TextBox Height="23" Margin="107,85,281,0" Name="txt_name" VerticalAlignment="Top" />
<Label Height="23" HorizontalAlignment="Left" Margin="25,89,0,0" Name="label2" VerticalAlignment="Top" Width="72">Name* :</Label>
<TextBox Height="23" Margin="107,118,281,0" Name="txt_cellno" VerticalAlignment="Top" />
<Label Height="23" HorizontalAlignment="Left" Margin="25,121,0,0" Name="label3" VerticalAlignment="Top" Width="72">Cell No.* :</Label>
<TextBox Height="23" Margin="107,0,281,173" Name="txt_add1" VerticalAlignment="Bottom" />
<Label Height="18.025" HorizontalAlignment="Left" Margin="25,0,0,176" Name="label4" VerticalAlignment="Bottom" Width="72">Address1 :</Label>
<TextBox Height="23" Margin="107,0,281,140" Name="txt_add2" VerticalAlignment="Bottom" />
<Label Height="23" HorizontalAlignment="Left" Margin="25,0,0,138" Name="label5" VerticalAlignment="Bottom" Width="72">Address2 :</Label>
<TextBox Height="23" Margin="107,0,281,107" Name="txt_city" VerticalAlignment="Bottom" />
I want to bind the ComboBox to the contact table with display member "Name" and value member "ContactID"
I tried different-different methods but nothing is working for me...
here's the code which gives error
DataClasses1DataContext db = new DataClasses1DataContext();
var sel = from contact in db.Contacts select new { contactid = contact.ContactID, name = contact.Name };
cbx_contact.ItemsSource = sel;
cbx_contact.DisplayMemberPath = "name";
cbx_contact.SelectedValuePath = "contactid";
I am getting the following error : Cannot create instance of 'Contact_form' defined in assembly 'WpfApplication2, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. Exception has been thrown by the target of an invocation. Error in markup file 'WpfApplication2;component/Contact_form.xaml' Line 1 Position 7.
And please give me links of good examples of binding wpf gridview. listview and combobox