Can't bind the content of a contentPresenter?

ContentTemplate is a template for content . So, in the case of ContentControl Content becomes DataContext of the DataTemplate . But you can't set Window as Content and the property you bind to has to be public.

Up vote 0 down vote favorite share g+ share fb share tw.

I can't figure out what I'm missing here. I want to bind the content of a ContentPresenter to a UIElement. I'm doing something like this: In MainWindow.

Cs UIElement Element { get; set; } public MainWindow() { Element = new TextBox() { Text = "A" }; DataContext = this; InitializeComponent(); } I can put the textBlock in directly, but when I try the ContentPresenter it does not display anything. C# wpf xaml data-binding link|improve this question edited Nov 17 '11 at 15:12Verbeia3,5141622 asked Jul 8 '11 at 21:13foo131117 69% accept rate.

ContentTemplate is a template for content. So, in the case of ContentControl, Content becomes DataContext of the DataTemplate. But you can't set Window as Content and the property you bind to has to be public.

So, after making Element public property and changing the XAML to: “A” is shown in the window. I'm assuming this isn't the real code where you encountered the issue, but doing something like this looks very odd. Maybe you should rethink your design.

Well put! First issue is 'Element' was not public. Second issue is that The ContentControl had no 'Content' and therefore the ContentTemplate had no content to use the template.

– Scott Jul 8 '11 at 21:54.

Binding works for the data. I don't think that it will work for it's visual representation.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions