It almost seems like a cruel joke. Innumerable WPF samples indicate that you can implement databinding in a particular way. However, doing so breaks designer support and you have to rearrange code to reflect the reality of current limitations with Cider. Let me explain what I mean.
When you create XAML markup you are declaratively creating objects with XML. Normally, the XAML tags will create controls like textboxes and labels, etc. But there is nothing to stop you from instantiating model objects in XAML. So, instead of writing
Person p = new Person();
in your code behind, you can instantiate a person like this
<Window.Resources>
<local:Person x:Key="myDataSource" Name="Joe"/>
or like this
<Window.Resources>
<ObjectDataProvider x:Key="myDataSource" ObjectType="{x:Type local:Person}" />
The XML namespaces (local and x above) have to be registered at the top of your file like this:
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:YourProjectNamespace"
You can then databind to the person object like this:
<TextBlock Text="{Binding Source={StaticResource myDataSource}, Path=Name}"/>
Make sure you put the Window.Resource element above the TextBlock element otherwise your datasource won't exist at the time you are databinding and you will get a null reference exception. Finally, can run the sample and it will execute perfectly. But don't venture into the designer! If you do, you get a nasty error in the error list:
Assembly '' was not found. The 'clr-namespace' URI refers to an assembly that is not referenced by the project.
There is no designer support for declaratively created model object in the current release that I know of. To get designer support for these types of pages, rip out the dynamically created object and change the codebehind to instantiate and object explicitly and bind up the object to the context.
public Window1()
{
InitializeComponent();
Parent p = new Parent();
this.DataContext = p;
}
Image may be NSFW.
Clik here to view.
