Geeks With Blogs


What I do:

Identity Mine

MVVM Light


What I am:

Microsoft Most Valuable Professional, Client Application Development

Microsoft Certified Technology Specialist, Windows Presentation Foundation

WPF disciples


View my profile on LinkedIn

Creative Commons License
Diary of a Code Trotter by Laurent Bugnion is licensed under a Creative Commons Attribution 3.0 Unported License

All source code on this blog is licensed under the MIT license.

Copyright (c) 2006 - 2011 GalaSoft Laurent Bugnion

Laurent Bugnion (GalaSoft) Diary of a Code Trotter
Continuing my quest to make my applications as "blendable" as possible, and after noticing that Expression Blend doesn't execute a Window's or a User Control's constructor when the element is displayed, I thought I'd try to place my test data in the XAML itself, using an XmlDataProvider. Unfortunately, it still doesn't work as well as I had hoped.
In order to allow designers to work in Expression Blend as much as possible, it is often necessary to create a test application. For example, the real data might not be available at design time. Or, if the data is available, it might be provided by an underlying service which Blend is unable to connect to (we saw in my previous post that Blend loads and executes the UI code in its AppDomain, but that the root element's constructor is not executed).
Now I am wondering where is the best place for the test data. Placing it in the test application's Window means that Blend cannot display it. Using a User Control to place the test data, and then placing the User Control in the Window allows Blend to display the data (again, see my previous post), however it doesn't allow selecting the elements in the User Control in order to style them. It would be nice if we could, in one single Blend window, see all the databound elements and select them to modify them.
The last idea
As last attempt before (probably) giving up, I thought that if the test data was placed in the XAML code inline, using a XmlDataProvider, maybe it would work better and the databound elements would be represented in Blend. Unfortunately, it's not the case.Here is what I tried:
<Window xmlns="" xmlns:x="" xmlns:src="clr-namespace:WindowsApplication4"
Title="WindowsApplication4" Height="300" Width="300" > <src:UserControl1/> </Window>
Window containing a User Control
<UserControl xmlns="" xmlns:x="" x:Class="WindowsApplication4.UserControl1" > <UserControl.Resources> <XmlDataProvider x:Key="data" XPath="/Labels"> <x:XData> <Labels xmlns=""> <Label name="label1"/> <Label name="label2"/> <Label name="label3"/> </Labels> </x:XData> </XmlDataProvider> <DataTemplate x:Key="dataTemplate"> <Border BorderBrush="Silver" BorderThickness="2" Background="Black" CornerRadius="8,8,8,8"> <Label Content="{Binding XPath=@name}" FontSize="24" FontWeight="Bold" Foreground="Silver"/> </Border> </DataTemplate> </UserControl.Resources> <Grid DataContext="{StaticResource data}"> <ListBox ItemsSource="{Binding XPath=Label}" ItemTemplate="{StaticResource dataTemplate}" Width="300" Height="300"/> </Grid> </UserControl>
User control, including inline XML data
Opening this code in Blend creates the following result:
User control: No data is displayed
User control: No data is displayed
Window: The data contained in the User Control is displayed correctly
Window: The data contained in the User Control is displayed correctly
It's time for me to give up on that quest. The designers will have to work on the templates (ControlTemplate, DataTemplate...) in Blend, will be able to see the results in Blend to some extent, but will need to run the application in order to see the whole extent of the functionalities. It's not that big a deal, because the application can be compiled and run (in debug mode) from Expression Blend directly. This is actually a great feature, because most designers won't install Visual Studio 2005. I will now work on recommendations for the WPF integrator for the workflow, maybe in the form of a checklist, and for the designers. In some cases, it is probably possible to work on the real, original application directly in Blend. In other more complex cases, a lean test application using the real, original resources will have to be built, and the WPF integrator will be in charge of this task.
Posted on Saturday, May 19, 2007 8:31 AM Technical stuff , .NET , WPF , Expression Blend | Back to top

Comments on this post: WPF: Data Binding in Expression Blend

Comments are closed.
Comments have been closed on this topic.
Copyright © Laurent Bugnion | Powered by: