Solved

Content Presenter (WPF)

Posted on 2014-04-08
3
230 Views
Last Modified: 2014-06-17
I am just looking through a sample piece of code

    <TabControl.ItemTemplate>
                    <DataTemplate>
                        <ContentPresenter Content="{Binding DisplayName}" />
                    </DataTemplate>
                </TabControl.ItemTemplate>

Why would they use a Content Presenter?
0
Comment
Question by:VisionTeknology
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 23

Expert Comment

by:Snarf0001
ID: 39987395
Can't really say in this case since I don't know the rest of the code, but:
ContentPresenter is very handing when overriding templates.

For example, if you were overriding the template of a label, to put it in a grid or stackpanel or something, then the ContentPresenter will render all of the xaml markup in the original control.

In this case, you could possibly have a list where the DisplayName actually has xaml in it,
<Label><StackPanel><TextBlock>Foo</TextBlock><TextBlock>Bar</TextBlock></Label>

For something like this, the only way to get it to actually render the xaml properly is using the content presenter.   If you just bound to another element, you would get a text version of the markup.


Now, in this particular case, I would be very surprised if DisplayName had anything other than a string in it, in which case using ContentPresenter is definitely overkill, but might be just to accommodate future expansions.
0
 

Author Comment

by:VisionTeknology
ID: 39988133
The binding is a string, could you not use a <TextBlock>?
0
 
LVL 23

Accepted Solution

by:
Snarf0001 earned 500 total points
ID: 39988461
Definitely, and would be lighter weight.  As I mentioned, it's probably just there for future expansion or something like that.
Textblock is 100% sufficient in this case.
0

Featured Post

Is Your Team Achieving Their Full Potential?

74% of employees feel they are not achieving their full potential. With Linux Academy, not only will you strengthen your team's core competencies but also their knowledge of of the newest IT topics.

With new material every week, we'll make sure that you stay ahead of the game.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question