tags:

views:

60

answers:

2

Why is that when I define a view with data context in this way:

<views:MessageView DataContext="{x:Type presenters:MessagePresenter}"/>

that my MessagePresenter does not run its constructor?

What is the syntax to define view/presenter pairs like this in XAML?

+4  A: 

{x:Type} returns the type of MessagePresenter, not an instance of MessagePresenter.

The following creates an instance of MessagePresenter:

<views:MessageView>
 <views:MessageView.DataContext>
  <presenters:MessagePresenter/>
 </views:MessageView.DataContext>
</views:MessageView>
Bubblewrap
A: 

x:Type is resolving a Type instance that represents the type in question (MessagePresenter in this case). It's not supposed to create an instance of the type.

HTH, Kent

Kent Boogaart