in

ExpressionBlog.com

Microsoft Expression Studio Community

This Blog

Syndication

Mirrored Blogs

Browse by Tags

All Tags » Data Binding (RSS)
  • Three New Videos On Data Binding

    I’m pleased to announce that we’ve posted three new videos on DataBinding and on DataTemplates (creating templates that control the display of a collection of data in a list control such as a list box) Unfortunately, we swapped the images for the Blend video and the Xaml video which is a bit confusing but we’ll get that fixed. And, while the three videos do stand alone, watching them in the order 37 –>39 -> 38 will make a good bit more sense <smile>. In any case, I hope you find them interesting and useful. The first, An Overview… explains the fundamental concepts of DataBinding and ListTemplates. The “second”, DataBinding and DataTemplates in Xaml shows how to bind the properties of business objects to Silverlight controls in Xaml and how to create DataTemplates by hand. Finally, the “third”, DataBidning and DataTemplates With Expression Blend recreates that same work using Expresion Blend (and note that it is 9 minutes vs. 22!).
  • Silverlight Debugging Challenge

    In about a week, I'll be posting a video on creating a form that responds to keyboard shortcuts (as an intro to a video on user controls). This is also covered in the tutorial User Controls ) As a challenge to those of you who are already comfortable with styles and data-binding and who "don't need no stinkin' video" -- I've posted a broken version of the program for you to debug. <chortle>   Your mission, should you decide to find it, is to find the bug, and fix it.             In the video I show this broken version and why it is broken, and then I fix it;  but if you'd like to get ahead of the curve and try your hand... have at it. It's a bit sneaky. What is supposed to happen when you run the app is that if you hit Control-C the address of the Computer Museum is filled in and if you hit Control-M the address of Microsoft is filled in.  But it don't. <cackle>
  • How do you know INotifyPropertyChanged is Working

    Today I had the great enjoyment to make two presentations to the Microsoft Health and Life Sciences Conference here in Atlantic City. While showing DataBinding, I became interested in demonstrating the effects of INotifyPropertyChanged, The basic mechanism is this; you add a PropertyChangedEventHandler to your business object and each time you set a bound property you invoke that event, passing in a reference to the business object and an instance of PropertyChangedEventArgs initialized with the name of the property The bound Silverlight controls will respond to this event and update themselves to the new value. But how to test this? We tried making a new browser, but no go; we suspected (correctly) that the UI was pointing to two different objects. I proved this to myself by modifying the constructor to generate a random number and store it in a member variable, which I display.   When you attempt to create two views on the data (by hitting control N on the browser or by copying the URL to a new tab) you generate a new object as you can see by the new ID.     To ensure that we're seeing the UI update in response to changes to the same object, it is easiest to just add two new rows, one that shows the value of IsPublished and the other that shows Quantity on Hand. When you change the original, the duplicate should be informed through the event.   We can now run the program again and when we change the isPublished or QuantityOnHand properties, we should see that immediately reflected in the second control. Turn off the notification and the reflection should stop.  
  • Binding Data How Do I Video Posted

    I'm pleased to say that we've posted a new How Do I Video on Binding Data to Silverlight 2 Controls. In the very beginning of this video I say it is about "wiring up events" but I'm confused and befuddled -- it is, of course, about binding UI objects to business objects. This is clarified quickly and there is no confusion once we get past the first few moments.
  • Tutorial: Data From a SQL DB via WCF (using LINQ)

    My 4th tutorial Displaying SQL Database Data in a DataGrid using LINQ and WCF is now available, as is the source code and a version of the tutorial in PDF For the moment, I recommend the PDF version as the images are clearer. We're fixing up the HTML versions of all the tutorials even as I write this. This tutorial walks through Creating a LINQ query against your SQL Server database Creating a WCF service to provide access to the results of your LINQ query Binding Silverlight 2 controls against the WCF service We will, over time have a way to provide direct feedback for each tutorial, but for now, please do send email or use the forums to ask questions about anything you read in the tutorials. Thanks again,   -jese
  • LINQ To SQL

    A number of folk have written to me in response to my 3rd tutorial asking that I spend some time focusing on how to obtain data from a SQL database. This is the topic for tutorial #4, to be released on April 1. A few interesting issues arose when writing that tutorial, and so I thought I'd start to discuss them even before the tutorial appears. Architecture The most straightforward way to deal with using Silverlight to present data from a Database is to create a Web Service whose job is to query the database in response to data coming from Silverlight and to return data in a form that your Silverlight application can use. Thus, the various skills that the tutorial must bring together include Creating a simple WCF Web Service Using LINQ to Sql to create the Queries Making sure the class is serializable Creating the Service Modifying the contract Implementing the contract Freezing the port Setting the Silverlight App to see the Web Service Calling a method in the service and getting back data Displaying the data Adding a DataGrid Understanding DataGrid properties Binding data to DataGrids While all of this is covered in the tutorial, there is plenty to dive into further, and I'll be doing so in this blog over the next few weeks. Using LINQ to Retrieve Data The tutorial assumes that you are somewhat familiar with LINQ. This new and powerful aspect of VB and C# is likely to be central to any Silverlight applications that interact with data, and you will want to take the time to learn about it (sooner or later). A good way to start is with ScottGu's tutorial - if you find you want more you might want to take a look at a good tutorial on VB 9 or on C# 3 (see some suggested titles at the bottom of this entry) Source Code To get started, open a new project of type WPF Application (!) -- We're going to do this in WPF to avoid dealing with web services for now. The point of this entry is just to look at the LINQ part. Visual Studio will set up your WPF application (look familiar? Isn't it cool how close WPF and Silverlight are? Don't get distracted! Pay attention in class!) Right click on the project and choose Add... When the Add New Item window opens, curse (again) that the Templates are not in alphabetical order and click on Linq To SQL Classes. Accept the default name (DataClasses1.dbml) and click Add. That will add DataClasses1.dbml to your project and open the Object Relational Designer which is just too cool a name. Open your Server explorer...
  • Tip of the Day - Binding to a Collection

    The Tip of the Day doesn't usually carry on a related series of postings, but data binding is so important that I'm making an exception this weekend. Yesterday we looked at laying out a form using a grid holding a DataGrid and a second grid to create a master detail relationship, with the end goal looking like this: To populate the DataGrid that we've placed in the left column of the outer grid, we'll need a collection of business objects. To keep this simple, I've returned to the idea of a book class, While it isn't strictly necessary for my Book class to implement INotifyPropertyChanged, it is convenient to have it do so, so that if the Book object is changed in the underlying data, the UI can be updated as well. Thus, each of the underlying private member fields  has a public property whose getter returns the private field and whose setter both sets the field and calls the Notify method to update the UI,   With the book class in place, it is easy to create a collection of Book objects based on the last few books I bought for my Kindle.  The steps are: Create a member variable to hold the collection Allocate memory for the collection Add objects to the collection Set the DataGrid to bind to properties of each individual object Set the collection as the ItemSource property of the DataGrid     Create a member variable to hold the collection Allocate memory for the collection Add objects to the collection You can imagine that we would normally be retrieving these objects from a database, web server, or other common data source. Here we are hand coding to keep life simple.       Set the DataGrid to bind to properties of each individual object   In this small snippet you can see that we've created an instance of the DataGrid, named it Books, placed it in the grid, and told it not to auto generate its columns (we only want two columns, not all of the properties of the Book!).  We then manually create two text box columns, one for the Title and one for the ISBN.   Set the collection as the ItemSource property of the DataGrid If you look closely at the line numbers you'll see that I cut out most of the "Add Book" calls to focus on the call to setting the ItemsSource on the DataGrid (look at line 23 in the previous image!).  By creating this binding, when the page loads the collection is bound to the data grid and the two properties from each book object are displayed...