I've a WPF application, with which I use Prism for the architecture.
I've something a little bit custom:
I've one UserControl(a wizard), that can receive a FrameworkElement
. This element is displayed within the wizard usercontrol with a ContentPresenter
.
Basically, the view that will use this usercontrol will have such code:
<UserControl x:Class"My.Instance"
//skipping namespaces
mvvm:ViewModelLocator.AutoWireViewModel="True">
<Wizard>
<Wizard.ContentElement>
<TextBlock Text="{Binding MyInstanceProperty}"/>
</Wizard.ContentElement>
</Wizard>
</UserControl>
Within the "Wizard" UserControl, I just have such thing:
<ContentControl Content="{Binding ContentElement}" Margin="10"/>
The context being the code behind of the usercontrol(set on the root Grid
).
On runtime, I've the following error
System.Windows.Data Error: 40 : BindingExpression path error: 'MyInstanceProperty' property not found on 'object' ''Wizard' (HashCode=29548405)'. BindingExpression:Path=MyInstanceProperty; DataItem='WizardViewModel' (HashCode=29548405); target element is 'TextBlock' (Name=''); target property is 'Text' (type 'String')
So it seems that my TextBlock has its DataContext set on the Wizard UserControl, but not on the "My.Instance" owner.
I guess, it's because I host it within a ContentPresenter?
How can I avoid this?