Silverlight DataBinding vs. CLR Objects in Blend
I love the feature in Blend where you can set up data binding to CLR objects and create your Silverlight control / page. My problem has to do with creating a custom control that will be used as a DataTemplate. This all works great in Blend, but only during development. The problem is when I edit the control in Blend and I bind the textbox to a property of the CLR object, it gives me this:
Text="{Binding Mode=OneWay, Path=TestAccount.Name, Source={StaticResource TestDataDS}}"
But when I'm ready to run my application and use this custom control in the DataTemplate, for example in a list box, I need it to look like this:
Text="{Binding Mode=OneWay, Path=Name}"
How can I use the excellent design bindings in Belnd, but don't have to touch / search and replace all those bindings when I'm ready to launch the project? I am looking for an approach that will work both at design time and runtime.
Thank,
To create a data binding to a CLR object in Expression Blend, you do not need to use the DataField tab of the Create Data Binding dialog box. In fact, this is done very rarely.
Using a custom path expression is the most common way. Just check the box next to "Use custom path expression" and then enter the name of the property you want to bind to. If you do not provide a data context, then data binding will be resolved for the path that you provided for any object that is a DataContext.
If you want to set the design-time of the DataContext, you can do so by setting the d: DataContext property, making sure you are defining the xmlns correctly: d = "..."
source to share
If you are using blend 2, I would recommend you take a look at Jonas Follesoe's design time / blog post time , which uses dependency injection.
If you are lucky enough to use Blend 3 check this out
When you set bindings to blend, is the Explicit Data Context tab available?
source to share