views:

30

answers:

2

Hi!

I created a user control called 'RibbonTabX' which contains a stackpanel named 'spMain'. What I'd like to do, is when I declare an instance of my 'RibbonTabX' in xaml, within that same xaml I'd like to specify controls which will be inside the child stackPanel 'spMain'. Here is the code which will make what I'm trying to do much clearer:

  <ribbon:RibbonTabX strHeaderText="Testing 123...">
          <ribbon:RibbonTabX.spMain>
              <sdk:Label Content="Hello" />
              <sdk:Label Content="World" />
          </ribbon:RibbonTabX.spMain>
   </ribbon:RibbonTabX>

In the parent of RibbonTabX, I want to specify child contents of the stackpanel within my user control 'RibbonTabX'. Just like you can do with a 'TabItem' control. Any ideas how I can do this?

Thanks!

A: 

You need to create a custom content control, not a user control.

Start with this article

It is more complex than a user control as you have to hand-craft a generic template for it, but they are more versatile.

Enough already
Perfect! That's just what I needed to know. Thanks!
Rob
A: 

You want to use a ContentControl. Rather than specify that those controls go in the stack panel you probably should just place the Content in the stack panel. Have your RibbonTabX derive from ContentControl rather than UserControl, then where it is appropriate put the <ContentPresenter /> then the user of the ribbon can put whatever into it.

<ribbon:RibbonTabX strHeaderText="Testing 123..."> 
          <StackPanel> 
              <sdk:Label Content="Hello" /> 
              <sdk:Label Content="World" /> 
          </StackPanel> 
</ribbon:RibbonTabX> 

Here is the most basic ContentControl possible:

<ContentControl x:Class="SilverlightControl1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"&gt;
    <Grid x:Name="LayoutRoot" Background="Orange">
        <ContentPresenter />
    </Grid>
</ContentControl>
Alex Lo
Great, Thank you!
Rob