<p>Can anyone point me to a good resource (or throw me a clue) to show me how to do DataBinding to controls (ComboBox, ListBox, etc.) in WPF?  I'm at a bit of a loss when all my WinForms niceities are taken away from me, and I'm not all that bright to start with...</p>

[{'answer_id': 7474, 'author': 'Matt Hamilton', 'author_id': 615, 'author_profile': 'https://Stackoverflow.com/users/615', 'pm_score': 3, 'selected': False, 'text': '<p>The best resource I\'ve found for WPF data binding is <a href="http://www.beacosta.com" rel="nofollow noreferrer">Bea Costa\'s blog</a>. Start from the first post and read forward. It\'s awesome.</p>\n'}, {'answer_id': 7475, 'author': 'Leon Bambrick', 'author_id': 49, 'author_profile': 'https://Stackoverflow.com/users/49', 'pm_score': 2, 'selected': False, 'text': '<p>in code behind -- set the DataContext of your list box equal to the collection you\'re binding to.</p>\n\n<pre><code>private void OnInit(object sender, EventArgs e)\n{\n  //myDataSet is some IEnumerable \n\n  // myListBox is a ListBox control.\n  // Set the DataContext of the ListBox to myDataSet\n  myListBox.DataContext = myDataSet;\n}\n</code></pre>\n\n<p>In XAML, Listbox can declare which properties it binds to using the "Binding" syntax.</p>\n\n<pre><code>&lt;ListBox Name="myListBox" Height="200"\n  ItemsSource="{Binding Path=BookTable}"\n  ItemTemplate  ="{StaticResource BookItemTemplate}"/&gt;\n</code></pre>\n'}, {'answer_id': 7479, 'author': 'Mark Glorie', 'author_id': 952, 'author_profile': 'https://Stackoverflow.com/users/952', 'pm_score': 3, 'selected': True, 'text': '<p>I find the tutorial videos at <a href="http://windowsclient.net/learn/videos_wpf.aspx" rel="nofollow noreferrer">Windows Client .Net</a> equally awesome. <a href="http://web.archive.org/web/20190214014927/http://www.dnrtv.com:80/default.aspx?showNum=101" rel="nofollow noreferrer">Dot Net Rocks TV</a> has also covered it some time ago.</p>\n'}, {'answer_id': 7519, 'author': 'Dhaust', 'author_id': 242, 'author_profile': 'https://Stackoverflow.com/users/242', 'pm_score': 2, 'selected': False, 'text': '<p>And some more links, just in case the above didn\'t suffice:  </p>\n\n<p><a href="http://msdn.microsoft.com/en-us/library/ms752039.aspx" rel="nofollow noreferrer">Windows Presentation Foundation - Data Binding How-to Topics</a><br>\n- Approx 30 \'How To\' articles from MSDN.<br>\n"The topics in this section describe how to use data binding to bind elements to data from a variety of data sources in the form of common language runtime (CLR) objects and XML. "   </p>\n\n<p><a href="http://www.codeproject.com/KB/WPF/MovingTowardWpfBinding.aspx" rel="nofollow noreferrer">Moving Toward WPF Data Binding One Step at a Time</a><br>\n- By WPF guru <a href="http://joshsmithonwpf.wordpress.com/" rel="nofollow noreferrer">Josh Smith</a><br>\n"This article explains the absolute basics of WPF data binding. It shows four different ways how to perform the same simple task. Each iteration moves closer to the most compact, XAML-only implementation possible. This article is for people with no experience in WPF data binding."</p>\n'}, {'answer_id': 7555, 'author': 'urini', 'author_id': 373, 'author_profile': 'https://Stackoverflow.com/users/373', 'pm_score': 2, 'selected': False, 'text': '<p>Here\'s another good resource from MSDN: <a href="http://msdn.microsoft.com/en-us/library/ms752347.aspx" rel="nofollow noreferrer">Data Binding Overview</a>.</p>\n'}, {'answer_id': 397832, 'author': 'Michael L Perry', 'author_id': 7668, 'author_profile': 'https://Stackoverflow.com/users/7668', 'pm_score': 2, 'selected': False, 'text': '<p>There are three things you need to do:</p>\n\n<ol>\n<li>Bind the ItemsSource of the ComboBox to the list of options.</li>\n<li>Bind the SelectedItem to the property that holds the selection.</li>\n<li>Set the ComboBox.ItemTemplate to a DataTemplate for a ComboBoxItem.</li>\n</ol>\n\n<p>So, for example, if your data context object is a person having email addresses, and you want to choose their primary, you might have classes with these signatures:</p>\n\n<pre><code>public class EmailAddress\n{\n    public string AddressAsString { get; set; }\n}\n\npublic class Person\n{\n    public IEnumerable&lt;EmailAddress&gt; EmailAddresses { get; }\n    public EmailAddress MainEmailAddress { get; set; }\n}\n</code></pre>\n\n<p>Then you could create the combo box like this:</p>\n\n<pre><code>&lt;ComboBox ItemsSource="{Binding EmailAddresses}" SelectedItem="{Binding MainEmailAddress}"&gt;\n    &lt;ComboBox.ItemTemplate&gt;\n        &lt;DataTemplate&gt;\n            &lt;ComboBoxItem Content="{Binding AddressAsString}"/&gt;\n        &lt;/DataTemplate&gt;\n    &lt;/ComboBox.ItemTemplate&gt;\n&lt;/ComboBox&gt;\n</code></pre>\n\n<p>Now you need to implement INotifyPropertyChanged in both Person and EmailAddress. For the EmailAddresses collection, you could back it with an ObjservableCollection.</p>\n\n<p>Or as an alternative you can use <a href="http://codeplex.com/updatecontrols" rel="nofollow noreferrer">Update Controls .NET</a>. This is an open source project that replaces data binding and does not require INotifyPropertyChanged. You can use whatever collection makes sense to back the EmailAddresses property. The XAML works the same as above, except that you import the UpdateControls.XAML namespace and replace {Binding ...} with {u:Update ...}.</p>\n'}]
['https://Stackoverflow.com/questions/7472', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/856/']