Building a WPF application, WPF DataBinding

Last night, after my WPF training, I decided to make a WPF application which can run on Media Center to play Last.FM streams and get info about my played tracks with of course some nice graphs :).
 
Last.FM has loads of webservices which geeks like me can use to get data, see http://www.audioscrobbler.net/data/webservices/.
 
Of course i want to use LINQ to get to my data, for those who are new to LINQ read this to get an idea how LINQ works.
 
There are a few ways you can get the data from the webservice to the XAML:
–  Get the data from the webservice in XLINQ and bind the the Context/Text property in Code (not recomended)
–  Open the data from the webservice in XLINQ and bind directly to the XAML datasource, read this great blogpost how to do this here
– Using LINQ to get data from the webservice and put them in classes, then bind the classes to the XAML datasource, read this blog post how to do this.
 
I used the second method for my app because it gets me the fastest results. But in the end i would like to go to the classes method.
 
The code i produced to get the data on screen:
In Main.xaml.CS:
 //Open Webservice
                XDocument userDocument = InitializeDataSource(@”http://ws.audioscrobbler.com/1.0/user/“+ username +”/profile.xml”);
                // Get the Root of the XML
                var UserInfo = userDocument.Root;
                //Bind the data to the PersonInfo stackpanel
                PersonInfo.DataContext = UserInfo;
In Main.Xaml:
 
           
 
So far my litte adventure in WPF, to be continued (took me a while to get my data onscreen).
 
A few intresting links about Databinding in WPF and LINQ:
http://www.beacosta.com/ (this blog rocks !)

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.