-
Drag-and-drop data binding helps you build business applications very easily, however sometimes you still need to customize the layout or format after data binding is set. For example, I built a simple application to display all the Customers, and for each Customer, the related Orders are loaded into a DataGrid control:
Of course the data in Birthday field is fake :) and of course I don’t want to show the time part 12:00:00 AM in the text. To customize the string format, first let’s go to the XAML file and locate the TextBlock which binds to Birthday:
<TextBlock Grid.Column="1" Grid.Row="3" Height="21" HorizontalAlignment="Left" Margin="3" Name="birthdayTextBlock" Text="{Binding Path=Birthday}" VerticalAlignment="Center" Width="120" />
You could write a converter to convert the string. Another simpler way is to insert a StringFormat property to the Text Binding and set it to only display the Date 1/1/2222:
Text="{Binding Path=Birthday, StringFormat=d}"
Similarly, if you set StringFormat to the “Order Date” and “Preferred Delivery Time” column:
…
<TextBlock Text="{Binding Path=OrderDate, StringFormat={}{0:dddd MMMM dd}}" />
…
<TextBlock Text="{Binding Path=DeliveryDate, StringFormat=t}" />
…
StringFormat={}{0:dddd MMMM dd} it will display the DateTime in your specified format; StringFormat=t will only display short time. Now the form looks like this:
Now you might ask, how about WinForms? It is just as easy.
On the left is the WinForm Designer surface. Set focus on the DateTimePicker control and find Format property in Properties window. Change the Format to Short so that Birthday TextBlock will only display the Date:
To set OrderDate column and PreferredDeliveryDate column to display in the format as in the WPF example above, click on the DataGridView control and click on the little smarttag button to open DataGridView Tasks:
Select Edit Columns to invoke Edit Columns dialog, and in Bound Column Properties, select DefaultCellStyle to launch CellStyle Builder:

There are some other customizations in this dialog, now let’s just focus on the Format. You could input Format like “dddd MM dd”, or launch Format String Dialog to set the string format. After setting format for both OrderDate column and PreferredDeliveryTime column, the final windows form is:
Well, isn’t it simple to change string format in data binding for both WPF and WinForm? To learn more about formatting (not only formatting DateTime string), please see: http://msdn.microsoft.com/en-us/library/fbxft59x.aspx
Cheers!
-
Visual Studio 2010 Beta1 provides a great feature called “Navigate To”. You can find this feature under the “Edit” menu or use the keyboard shortcut “Ctrl + COMMA” to bring up the “Navigate To” dialog. This feature provides search-as-you-type support for files, types, and members to match the input string. Following is a snapshot of the “Navigate To” dialog:
Here are some summaries for this feature:
1. If the search string contains uppercase characters, the search is case-sensitive; otherwise not.
2. The white space between characters will be treated as an 'and' relationship.
3. The search does not support wildcard.
This feature becomes extremely handy when your solution/project is complex. The search result comes very quickly even for large solutions.
You can find more information about this feature at the following link: How to: Search for Objects, Definitions, and References (Symbols).
Also, a walkthrough is provided: Walkthrough: Quick Search for Files and Symbols in Visual Studio 2010.
Enjoy!
-

May 11 – 15, 2009. Los Angeles.
It is always exciting to attend conferences like TechEd and talk to the users like you! I attended Teched 2009 North America, which took place in Los Angeles last month, as a Visual Studio staff, and spent 20+ hours standing at Visual Studio booth. I really enjoyed experiencing TechEd once again and enjoyed the moments when you told us the products are helping to do your daily work more efficiently. Hearing your feedback is also very important to us, and it is exactly the reason why we are there at the conference! For those who were also at TechEd this year, I hope you enjoyed the sunshine in LA and liked hundreds of sessions there!
This year, Windows 7 and Windows Server 2008 R2 drew a lot of attentions. Mark Russinovich, who is a Technical Fellow at Microsoft, demoed quite some new Windows 7 features at keynote on the first day.
- One of my favorite features in Windows 7 is the Problem Steps Recorder which helps customers (or friends, or family) to easily record what they did and what happened on their machine instead describing the repro steps, therefore it’ll largely help the ITPros to understand and troubleshoot the problems.
- Another highlight in Windows 7 is AppLocker feature, which helps IT Admins to easily specify what is allowed to run on user desktops and creates a secure environment.
Windows 7 demo is followed by Windows Server 2008 R2 demos by Iain McDonald, including the File Classification Infrastructure which helps ITPros to establish policies for classifying files and then performing common administrative tasks based on the classification.
Another hot topic at TechEd was Silverlight 3. (download Silverlight 3 Beta 1) If you are still wondering if you should choose Silverlight to build line of business applications, you should definitely try out Silverlight 3! Silverlight 3 has made Silverlight ready for building data-driven applications than ever before! A few Silverlight 3 controls that you might be interested in your business applications:
- ChildWindow
- DataForm
- DataGrid
- DataPager
- Navigation (Frame, Page, Deeplinking..etc.)
- Validation UI (ErrorSummary)
These controls are available for download at Silverlight Toolkit Sample.
Besides Silverlight 3 new controls, .NET RIA Services (download ".NET Ria Services" March 2009 preview) is the other essential piece that makes build Silverlight business applications much easier. In short -
Microsoft .NET RIA Services simplifies the traditional n-tier application pattern by bringing together the ASP.NET and Silverlight platforms. The RIA Services provides a pattern to write application logic that runs on the mid-tier and controls access to data for queries, changes and custom operations. It also provides end-to-end support for common tasks such as data validation, authentication and roles by integrating with Silverlight components on the client and ASP.NET on the mid-tier.
".NET Ria Services" March 2009 preview provides a great overview document that introduces .NET RIA Services in details, and it also described an end to end walkthrough for you to get started. Start building your Silverlight business applications today!
It is great to see .NET RIA Services generated huge interests at TechEd, as our team is also working on some of the features in there. :) Please let us know if you have any comments and suggestions once you have tried it out. You are more than welcome to leave comments here or post at .NET RIA Services forum.
Next year, TechEd will be back in New Orleans, June 7-11, 2010.

See you there!
-
You may have known that drag-drop data-binding experience has been introduced to WPF application development story from VS2010 Beta1, thanks to a lot of posts before this one. The whole experience in WPF is pretty similar to what we’ve already had with WinForms: developers configure the bindings in Data Source Window and associate controls with data entities or properties, and drag-and-drop from Data Source Window to the designer generates controls with data binding set in the code. All looks familiar. But wait a second, you may find there is still something missing if you tend to generate a DataGrid or DetailsView for a data entity. You are right. In WPF, there’s no navigation bar facility, so drag-and-drop will only leave the exact control you are binding with the entity. However, using WPF, you will find it’s easy to do data navigation, thanks to the CollectionViewSource. So why not build your own one and make it as whatever you like?
In this article, we will build a simple navigation bar leveraging CollectionViewSource. Below is what it looks like:

To start, we use drag-drop WPF data-binding feature in VS2010 Beta 1 to generate a Details View of Employee entity. We use EDM here as data source. Let’s update the generated code behind a little bit and declare the entity, the CollectionViewSource, and the query in a class wide. We also need to declare an int field member to get the total row counts of an entity, which looks like below:
public partial class Window1 : Window
{
private WpfDataNavigationApplication.NorthwindEntities northwindEntities = new WpfDataNavigationApplication.NorthwindEntities();
private System.Windows.Data.CollectionViewSource employeesViewSource__NorthwindEntities;
private System.Data.Objects.ObjectQuery<WpfDataNavigationApplication.Employee> employeesQuery;
private int totalRowCount;
public Window1()
{
InitializeComponent();
}
private System.Data.Objects.ObjectQuery<Employee> GetEmployeesQuery(NorthwindEntities northwindEntities)
{
// Auto generated code
System.Data.Objects.ObjectQuery<WpfDataNavigationApplication.Employee> employeesQuery = northwindEntities.Employees;
// Returns an ObjectQuery.
return employeesQuery;
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
employeesViewSource__NorthwindEntities = ((System.Windows.Data.CollectionViewSource)(this.FindResource("employeesViewSource__NorthwindEntities")));
employeesQuery = this.GetEmployeesQuery(northwindEntities);
employeesViewSource__NorthwindEntities.Source = employeesQuery.Execute(System.Data.Objects.MergeOption.AppendOnly);
}
}
Then it’s the time to build the navigation bar! Let’s start with UI design and make something like this:

From the left to the right, they are buttons for navigation to the first row, the previous row, the next row, and the last row; a text box for users to input the index of the row for navigation; a label to show how many row in all; and a button for navigation to the specific row based on what users input into the text box. We also add event handler for each button. The XAML of this navigation bar looks like below:
<StackPanel Height="28" HorizontalAlignment="Left" Margin="10,12,0,0" Name="stackPanel1" VerticalAlignment="Top" Width="206" Orientation="Horizontal">
<Button Content="|<<" Height="23" Name="goToFirstButton" Width="Auto" FontWeight="Bold" Background="BlanchedAlmond" Click="goToFirstButton_Click"></Button>
<Button Content="<" Height="23" Name="goToPreviousButton" Width="Auto" FontWeight="Bold" Background="BlanchedAlmond" Click="goToPreviousButton_Click"></Button>
<Button Content=">" Height="23" Name="goToNextButton" Width="Auto" FontWeight="Bold" Background="BlanchedAlmond" Click="goToNextButton_Click"></Button>
<Button Content=">>|" Height="23" Name="goToLastButton" Width="Auto" FontWeight="Bold" Background="BlanchedAlmond" Click="goToLastButton_Click"></Button>
<TextBox Height="23" Name="goTextBox" Width="37" />
<Label Content="of " Height="28" Name="label1" Width="20" />
<Label Height="28" Name=" totalRowCount" Width="25" />
<Button Content="Go!" Height="23" Name="goButton" Width="Auto" Background="BlanchedAlmond" FontWeight="Bold" Click="goButton_Click"></Button>
</StackPanel>
And in the code behind, we get a set of event handler methods for each button’s Click event.
Now it’s the time to implement navigation! Still remember we load data into a CollectionViewSource? Now it’s the time to leverage its power. CollectionViewSource is actually a XAML proxy for CollectionView class, which represents a View for grouping, sorting, filtering and navigating a data collection. The View provides a currency point and allows you to move the pointer. As a proxy of CollectionView class, CollectionViewSource has a View property, which is a dependency property. We’ll use this to move the currency and do navigation. So, for each Click event handler, the implementation is somewhat like below:
private void GoToFirstButton_Click(object sender, RoutedEventArgs e)
{
employeesViewSource_NorthwindEntities.View.MoveCurrentToFirst();
}
private void GoToPreviousButton_Click(object sender, RoutedEventArgs e)
{
employeesViewSource_NorthwindEntities.View.MoveCurrentToPrevious();
}
private void GoToNextButton_Click(object sender, RoutedEventArgs e)
{
employeesViewSource_NorthwindEntities.View.MoveCurrentToNext();
}
private void GoToLastButton_Click(object sender, RoutedEventArgs e)
{
employeesViewSource_NorthwindEntities.View.MoveCurrentToLast();
}
private void GoButton_Click(object sender, RoutedEventArgs e)
{
int position;
int.TryParse(goTextBox.Text, out position);
if (position > 0 && position <= totalRowCount)
{
employeesViewSource_NorthwindEntities.View.MoveCurrentToPosition(position - 1);
}
else
{
MessageBox.Show("The input index is not valid.");
}
}
To get the total row counts, we need to use the Count method in entity’s ObjectSet. Let’s put the following code into the Window_Loaded method:
totalRowCount = northwindEntities.Employees.Count();
totalRowCountLabel.Content = totalRowCount;
So far, we’ve already had our navigation work. Pretty simple, isn’t it? To make it even better, let’s do something more on the button, and disable the button when it doesn’t make sense to click it. We’ll add a new method here to set buttons’ ability:
private void SetButtonIsEnabled()
{
goToNextButton.IsEnabled = goToLastButton.IsEnabled = !isLast;
}
Also, we’d like the index input text box always shows the corresponding index number for the current selection. So we need another method here:
private void SetGoTextBoxOnCurrentPosition()
{
goTextBox.Text = (employeesViewSource__NorthwindEntities.View.CurrentPosition + 1).ToString();
}
Then we can call these two methods in the Click event handler methods (or wrap these two methods into a new method, say UpdateNavigatorUI, and call the method), and we’ll get a complete functionality of a basic navigation bar. The full code can be found here.
Based on that, we can add even more features into our navigation bar. To make it more powerful, you can also add CRUD functionality into it. However, hmm… In this article, the navigation bar we build only work for one page and one entity. There still some work we can do to make this useful utility more reusable. How we can do that? Bingo! Building a user control. And we will talk about that in the future post. Wait and see!
-
A few weeks ago I wrote about creating a master-details form, where we looked at an example of a database used for tracking orders, as part of an order management system. We had used the Customers and Orders tables and built a master-details form that showed a list of customers and for each selected customer, their orders. Another common scenario for binding related tables on a form involves look up tables.
Beth Massi wrote about how to data bind WPF lookup comboboxes to entities using VS2008. She uses describes the XAML and the code behind one needs to write to accomplish this. In VS2010, it’s considerably easier. Here’s how:
We will use the same Customers and Orders tables and entities that Beth uses (and we’ve used in my previous master-details post). Once we create a WPF application and add an entity model to to it as described in earlier posts, we should be able to browse the entity model in the data sources window. In the data sources window:
- Expand the Orders node and under it set the FK_Orders_Customer to a combobox
- Select the Orders node and set the control to Details view
- Drag and drop the Orders entity to the WPF form
- Now drag and drop the LastName property under FK_Orders_Customer to the combobox on the form.
Just these four simple steps will get the look up binding setup. The application, when run, would look something like this:
The XAML for the combobox is something like this:
<ComboBox Name="CustomerComboBox"
Height="23" Width="120"
HorizontalAlignment="Left" VerticalAlignment="Center" Margin="3"
DisplayMemberPath="Customer.LastName"
ItemsSource="{Binding}" >
-
I was browsing Channel 9 today, and saw the video Mark Wilson-Thomas demonstrating the easy drag-and-drop way of creating a Master Detail Form in WPF. Please check it out here. In some other videos, he also talked about the future of WPF designer, which is pretty cool.
Milind Lele also made two videos talking about the VS2010 drag-drop data binding feature. Any feedback or suggestion would be much appreciated!
This is not the only thing that got my attention on Channel 9. I’m sure most of you are excited about Windows 7 as much as I am – I have both my laptop and desktop running Windows 7 RC and I’m a big fan! Besides the Windows 7 videos on Channel 9, the Windows 7 RC Training Kit is available for download too. Follow the 7 Hands-on Labs, you’ll learn how to write a Windows 7 compatible application, and make use of the Windows 7 style Taskbar, Ribbon, Libraries, etc. Hopefully in the future, some tooling support will come out and help developers build Windows 7 applications more easily!
Cheers!
-
The MSDN CodeGallery now has VB and C# sample for WPF data binding
http://code.msdn.microsoft.com/WPFDatabinding
This is a sample of a WPF application and includes data binding, data validation, lookup binding. The solution is VS2010 Beta1 based, but the application uses .NET Framework 3.5.
See also: Beth Massi’s WPF Forms over data videos using VS2008
-
Recently I have been working with some Visual Studio feedbacks reported through Microsoft Connect. I found that some feedbacks may contain multiple unrelated issues. On the other hand, one issue may be reported several times by the same person in different feedbacks. There are also issues about crashing, memory, performance, debugging, etc. I will share some tips here that I think can benefit both Microsoft and our customers.
1. Report only one issue in one feedback. As you may know that there are many teams working for Visual Studio and Dot Net framework. Different issues are more likely handled by different teams, product units or even divisions. Multiple issues in one feedback will be hard to track and individual issues may not be routed to the right team promptly.
2. Do come back to check the feedback often. We may often ask for detail repro information in order to reproduce the issue. If the issue has been resolved as not repro but you have more info, don’t worry or get angry, just reactivate the issue and adding the new information. Some customers tend to open new feedbacks in this case. I think stick to the old issue and continue the communication would be a better approach. Of course, if the time span is too long, a new issue is appropriate.
3. When a crashing occurs and you see the dialog asking you to send the feedback, click the send button. This will send the important crashing information (like call stack) to Microsoft and the information will be analyzed.
4. If you have issues regarding crashes, hangs, slowness, or out of memory errors, you can collect the information with the performance diagnostic tool available here (you need to log in as a connect user first).
5. If you want to use the VS debugger to get a call stack or dump file of an exception of VS, you can do so with a second instance of Visual Studio, see the post I have here .
Hope this helps.
-
If you want to use the VS debugger to get a call stack or dump file of an exception of VS. You can do so with a second instance of Visual Studio. Here is the steps I would use:
| 1) Have your working Visual Studio running: let’s call this Visual Studio as VS1. Proceed to the point right before the exception is about to happen. 2) Open a second instance of Visual Studio (make sure this is the only second instance): let’s call it VS2. 3) Setup VS2 debug option as following a. Open Tools Option menu b. Drill down to Debugging\General, find out the Enable Just My Code (Managed Only) item, and uncheck it. c. Drill down to Debugging\Symbols, Set your symbol path to http://msdl.microsoft.com/download/symbols and cache the symbols to local directory like c:\symbols  d. Click OK to close down the dialog (note the debugger may take long time to down load the symbols for the first time, once the symbols are cached, it will be faster next time). 4) In VS2, attach the process of VS1 a) Open Debug\Attach to process… menu command b) In the Attach to Process dialog, Set Attach to parameter by click the Select button (see the picture bellow) · Set to Managed code only if you want to debug only managed code (it will be faster to choose the small set of debugging type) · Set to Native code only if you want to debug only native code. · Set both or automatic if not sure. If you need to save the dump file, you need to include the native code. c) Then double click on the devenv.exe from Available process  Devenv.exe is the visual studio instance. 5) Enable break on exception a) In VS2, open Debug\Exceptions menu and check on Common Language Runtime Exceptions for managed code. Add other checks if necessary. b) Clock OK to close the dialog.  6) Now go back to VS1, use the VS to allow the exception occur. 7) You should see the exception captured by VS2. 8) In VS2, open Debug\Windows\Locals to see the current exception a) Make sure the exception is the right one, hit F5 to continue to the next exception if necessary 9) In VS2, open Debug\Windows\Call Stack to get the call stack window. a) Copy the full stack and send back to your Microsoft representative. 10) Get dump file. If you include the native code debugging, you can use Debug\Save dump file as menu to save dump file. Send the dump file to Microsoft representative. |
| |
I am using Visual Studio 2008 as the example above. Other versions should have similar steps.
Also notice that if you have issues regarding crash, hang, slowness, out of memory error, you can collect the information with the performance diagnostic tool available here.
-
Check out this excellent article:
http://windowsclient.net/wpfdesigner/articles/first-wpf-application.aspx
The article walks you through creating a basic WPF application.
“You will learn to easily create, move and align controls, create data bindings and edit control collections using the powerful features of the WPF Designer for Visual Studio 2010.”
Oh, and by the way, there is also a video that shows this http://windowsclient.net/learn/video.aspx?v=171694
-
In Visual Studio 2010 Beta1, we have enabled data binding experience for a few data sources on WPF designer. Generic object or business object is one of them. Besides this, we have also supported multiple object selection in data source configuration wizard. I will show you all of the above features by walking through one example. In this example, I want to create a master-details form on a WPF designer by binding to the generic objects.
First, let’s create two classes called Customer and Order. And we establish one-to-many relationship between Customer and Order. This step is pretty similar to what needs to be done on a Winform designer.
Second, let’s add these two generic objects to data sources window. As I mentioned above, we now support selecting multiple objects in data source configuration wizard simultaneously.
After the addition, this is what displays in data sources window.
Third, let’s drag-drop from data sources window to the WPF designer to create a master-details form. We can bind any system or user controls to a particular data node. Here are the helps on “Customize Control Binding Dialog Box” and “How to: Add Custom Controls to the Data Sources Window”. In this example, I bind ListBox to the node Customer.LastName and DataGrid to the node Customer.Orders in the data sources window, and drag-drop these nodes to the WPF designer respectively.
Last, we need to fill the data to the form. In the third step, when we drag-drop the data nodes to the form, XAML code was automatically generated. That XMAL code is very similar to the one if we bind data to ADO.NET Entity Data Model. You can find detailed explanation about XAML code part in MilindLele’s post “WPF Data Binding: Creating a Master-Details form in Visual Studio 2010”. For the code behind the form, we set the data to the source property of the CollectionViewSource of the Customer object in the window loaded event handler.
List<Customer> customers = new List<Customer>();
customers.Add(...);
System.Windows.Data.CollectionViewSource customerViewSource =
((System.Windows.Data.CollectionViewSource)(this.FindResource("customerViewSource")));
customerViewSource.Source = customers;
Now press F5, we should be able to see the form loaded with the data.

As the master-details association is already created in XAML, different sets of orders will be displayed according to the selection of customer names.
-
In Visual Studio 2010 Beta1, the data binding experience with ADO.Net Data Services has been improved. In Visual Studio 2008 SP1, after adding an ADO.Net data service as web reference to a client project, it will not automatically show up in the data source window, you have to add an object data source to consume the ADO.Net data service. There is no more of this step in VS2010!
Let's take a look at the article of Walkthrough: Creating and Accessing an ADO.NET Data Service in Visual Studio (this is for VS2008 SP1). To create the client application consuming the ADO.Net data service, you have the following steps:
1) Create the client application
(Steps omit here)
2) Add a service reference
a) On the Project menu, click Add Service Reference.
b) In the Add Service Reference dialog box, click Discover.
The URL for the NorthwindCustomers service will appear in the Address field.
c) Click OK to add the service reference.
3) Enable data binding to the service
a) On the Data menu, click Show Data Sources.
b) In the Data Sources window, click Add New Data Source.
c) On the Choose a Data Source Type page of the Data Source Configuration Wizard, click Object, and then click Next.
d) On the Select the Object You Wish to Bind to page, expand the NorthwindClient node, and then expand the NorthwindClient.ServiceReference1 node.
e) Select Customers, and then click Finish.
4) Create the user interface
(Steps omit here)
In VS2010 beta1, you do not need to do step 3 anymore. ADO.Net data service is recognized automatically and happily shows up in the data source window. Alternatively, you can also add the ADO.net data service to your client project by the Data Source Configuration Wizard. Replace the step 2 above with the following:
a. On the Data menu, click Show Data Sources.
b. In the Data Sources window, click Add New Data Source.
c. On the Choose a Data Source Type page of the Data Source Configuration Wizard, click Service, and then click Next. The next page will be the Add Service Reference dialog box. Now you just do the same thing just as adding the service reference through Add Service Reference project menu.
At the end of Add service reference or the Data Source Configuration Wizard, you will see the following in the data source window (for the example in the walkthrough).
Even more, if you update the ADO.Net data service, e.g. adding Orders to the EDM, and update the service reference, the data source window will update accordingly as the example shown bellow.
Cheers!
-
Sine we released Visual Studio 2010 Beta 1 to the public on Wednesday (as Yang mentioned here) I thought it would be helpful to highlight some of the resources we have published to help you get started building business apps in your shiny copy of VS2010 Beta 1. Teams are really thirsty for feedback, so visit the Beta 1 forums and tell them what you think.
First, if you haven’t already, you’re going to need to download the Beta. ;-)
Then check out these resources:
- WPF Data Binding: Creating a Master-Details form in Visual Studio 2010
- Accessing Data in Visual Studio
- Visual Studio 2010 and .NET Framework 4.0 Training Kit
- Visual Studio 2010 Samples
Also, we just posted a Channel 9 interview with Matt Gertz, the guy in charge or coordinating the Visual Studio build. He explains how the build and test processes work here in DevDiv and I have to say it’s very impressive. He also talks about some of his favorite Visual Studio 2010 features.
In the coming weeks, the team here will be posting more about Visual Studio tools so make sure to subscribe to the feed.
Enjoy,
-Beth Massi, Visual Studio Community
-
Visual Studio 2010 Beta is released. Late last year we had released a Community Technology Preview (CTP) of VS2010. At that time I had written about some improvements to the data binding improvements for WPF. The Beta has many more and we will discuss them on this blog in a series of posts.
In my blog post last November I wrote about the newly added support for drag-drop data binding for WPF and that, like DataSets, EDM is one of the data sources supported by the data sources window. This post is about building a master-details form in WPF against an Entity Data Model. We will talk about the user experience, but more importantly about what code/XAML gets generated – at least the aspects that are relevant to master-details data binding.
The experience is very similar to WinForms over DataSets. Let us take the example of two tables: Customers and their Orders and create a form that lists the names of customers and for each customer, their orders.
As described in my earlier post, we can add an EDM to our WPF project and have it contain the two corresponding entities.
Here’s what you would see in the data sources window:
Here is how we can create the master details form:
- From the tool box drag-drop a ListBox onto the form.
- From the data sources window drag-drop the LastName column of Customer entity onto the ListBox
- Drag-drop the Order Entity from under the Customer node beside the ListBox on the form.
That’s it, really. You can press F5 to run the application and you will see your basic master-details form working. The customers list box will show a list of customer names and for the selected name the orders DataGrid will show their orders.
First, if you look at the XAML that gets generated, under Windows.Resources you will find two CollectionViewSource entries: One for Customers and one for Orders. These serve as the binding components (like the BindingSource objects in WinForms).
<CollectionViewSource x:Key="CustomersViewSource__OMSEntities" d:DesignSource="{d:DesignInstance my:Customer, CreateList=True}" />
<CollectionViewSource x:Key="CustomersOrdersViewSource" Source="{Binding Path=Orders, Source={StaticResource CustomersViewSource__OMSEntities}}" />
But note that the source for the CustomersViewSource__OMSEntities is the Customer entity, where as the source for CustomersOrdersViewSource is the CustomersViewSource__OMSEntities. Thus there is a master-details relationship between the two CollectionViewSouce objects. Now customer list is bound to CustomersViewSource__OMSEntities and the orders DataGrid is bound to CollectionViewSouce.
One more thing: We set the IsSynchronizedWithCurrentItem property of the customers list box to True. That way every time you change the selection in the listbox the current item in the CollectionViewSource is updated.
Second, if you look at the code behind the form, you will find that code to load the data for the entities is generated in the form’s Loaded event handler. In this code we build the object query for Customers and their orders, execute the query and assign the results to the source property of the CollectionViewSource of the Customers entity.
We construct the query in the GetCustomersQuery method. The basic query that loads customers and their objects is:
Dim
CustomersQuery As ObjectQuery(Of Customer) = OMSEntities.Customer.Include("Orders")
However normally you would want to filter the query, and return only the subset of the results that are relevant. Modify the query in the GetCustomersQuery method to include your Where condition.
-
This Monday, we released Beta1 of Visual Studio 2010 and .NET FX 4 to MSDN subscribers. Today it is publicly available for the rest of the world! Please visit MSDN Beta1 Landing Page to download.
The Beta1 release includes many interesting features. You might have already heard about some of them, and you could visit the Visual Studio 2010 Product Page to learn more. I am personally very excited about this release and I’m using some of the new features in my daily life now.
Of course, I’m more excited about the new features we enabled for Business Application developers. Milind talked about Drag-Drop Data Binding For WPF before. That is the user scenario we enabled in the CTP. With the Beta1 release, we support not only Entity Data Model, but DataSet, ADO.NET Data Service, Generic Object, and WCF Service. You could find more resources on MSDN Beta1 Walkthrough Page. We will also write follow-up posts here, so please stay tuned!
Besides the drag-drop data binding scenario, we also updated the Class Designer to support new features in C# and VB languages, including Auto-Implemented Properties, Optional Parameters, and Dynamic Types.
There is still a lot for us to do and your feedback is extremely valuable to us. We’d like to hear from you, so if you have feedback, please leave a comment on this blog, post your questions on the Visual Studio 2010 & .NET Framework 4 Beta 1 Forums, log a bug or suggestion on Microsoft Connect Beta 1 Feedback Page.
Cheers!