views:

216

answers:

2

So far, I have this:

<UserControl
    x:Class="MyConcept.ExpanderPanel"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"&gt;
    <Grid>
        <Border
            Style="{StaticResource Border_PanelStyle}"
            CornerRadius="3" />
        <ContentPresenter />
    </Grid>
</UserControl>

Sample usage of this UserControl:

<nc:ExpanderPanel
    Grid.Row="0">
    <Expander
        IsExpanded="True"
        Header="NMT Users">
        <StackPanel>
            ...
        </StackPanel>
    </Expander>
</nc:ExpanderPanel>

Discussion

If I run this, I see nothing. No content is presented, not even the border that is built into the UserControl.

I thought maybe I needed to make the ContentPresenter a dependency property, but I couldn't figure out how I would link the property to the ContentPresenter in the UserControl's XAML.

Can someone provide a simple example that shows how to build a UserControl (or some kind of custom control) with a single ContentPresenter?

+1  A: 

ContentPresenters are main used in ControlTemplates and bound with a TemplateBinding to the ContentControl.Content. from this site... a control template for a button that uses a ContentPresenter

<Style TargetType="{x:Type Button}">
  <Setter Property="Background" Value="White" />
  <Setter Property="Template">
    <Setter.Value>
      <ControlTemplate>
        <Grid>
          <Rectangle Fill="{TemplateBinding Property=Background}" />
            <ContentPresenter
              Content="{TemplateBinding Property=ContentControl.Content}" />
        </Grid>
      </ControlTemplate>
    </Setter.Value>
  </Setter>
</Style>
Muad'Dib
Your answer is blank :(
DanM
lol actually it is full of XAML that was not formatted as code. fixed it
Muad'Dib
It shows up now, but I'm not sure how this relates to my question. I'm trying to build a custom control or user control that contains a `ContentPresenter`, not set the ControlTemplate for a button.
DanM
you have to use a ControlTemplate for your control, this is an example of how to do so. Basically, you have to tell the ContentControl HOW to display what you want it to display. It has a set of "default" templates for some built-in things. http://social.msdn.microsoft.com/forums/en-US/wpf/thread/a2988ae8-e7b8-4a62-a34f-b851aaf13886#contentpresenter
Muad'Dib
+1  A: 

This looks like it will do the trick:

http://blog.pixelingene.com/?p=24

DanM