Wpf contentcontrol binding not updating
So I have a template containing a Text Box, and I have a View Model object containing a Name property, and I bind the Text property of the Text Box to the Name property of the View Model, and ... I've checked the visual tree with Snoop, and it confirms that the Data Context of the Text Box is the View Model object. And if I modify the (empty) Text in the Text Box, the Name property in the View Model does not change.
So it looks like the binding is not being applied (or has been removed somehow). Load Content does not preserve bindings - apparently Data Template. So it looks like I have to write my own version of Load Content(). Load Content(), but I realised that I didn't actually need a Data Template, since the Xaml Writer / Xaml Reader was already instantiating the UI element that I was after.
Setup the main dialog When I need quick prototypes, I often don’t use Blend and type the XAML directly into Visual Studio editor.
Using MVVM it took me about 10 minutes to create the basic structure of the dialog withouth writting a single line of code in the files.
Binding Expression: Path=Content Two Template Selector; Data Item='String' (Hash Code=-1506748533); target element is 'Content Presenter' (Name=''); target property is 'Content Template Selector' (type 'Data Template Selector') System. Data Error: 40 : Binding Expression path error: 'Content One Template' property not found on 'object' ''String' (Hash Code=-694847)'.
Binding Expression: Path=Content One Template; Data Item='String' (Hash Code=-694847); target element is 'Content Presenter' (Name=''); target property is 'Content Template' (type 'Data Template') System. Data Error: 40 : Binding Expression path error: 'Content One Template Selector' property not found on 'object' ''String' (Hash Code=-694847)'.
A quick post here about using a Content Presenter (or a Content Control which uses a Content Presenter in its template) with its Content property.
The intended usage of Content Presenter is to set the Content to some binding to a data object, then control the element tree via the Content Template property.
Search for wpf contentcontrol binding not updating:
Most of the resources on the web specify that Content Presenter supports a special property called Content Source, with a default value of “Content“, which makes it easy for it to automatically set the values of these properties used to render content: Basically, the property specifies the string prefix used to bind to properties of the parent.