tags:

views:

85

answers:

1

I want to make an ItemControl that provides some of its own children, and then when used can add additional children, similarly to the built in Expander class.

However, in this example, the Header TextBlock is also removed. This is a rephrasing of a question I asked yesterday (http://stackoverflow.com/questions/2277309/wpf-usercontrol-with-multiple-children).

LayerPanelItem.xaml:

<ItemsControl x:Class="Controls.LayerPanelItem"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"&gt;

    <StackPanel>
        <TextBlock>Header</TextBlock>
        <StackPanel Name="InnerContent">
            <!-- Test 1 and Test 2 should go here. -->
        </StackPanel>
    </StackPanel>

</ItemsControl>

Main.xaml:

<controls:LayerPanelItem>
    <TextBlock>Test 1</TextBlock>
    <TextBlock>Test 2</TextBlock>
</controls:LayerPanelItem>
A: 

If I'm understanding you correctly, you want more of a HeaderedItemsControl. Expander derives from HeaderedContentControl and this adds in the ItemsControl behavior to that:

<HeaderedItemsControl x:Class="WpfApplication1.LayerPanelItem"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"&gt;
    <HeaderedItemsControl.Template>
        <ControlTemplate TargetType="{x:Type HeaderedItemsControl}">
            <StackPanel>
                <ContentPresenter ContentSource="Header"/>
                <ItemsPresenter/>
            </StackPanel>
        </ControlTemplate>
    </HeaderedItemsControl.Template>
    <HeaderedItemsControl.Header>
        <StackPanel>
            <TextBlock>Header</TextBlock>
            <TextBlock>Other stuff...</TextBlock>
        </StackPanel>
    </HeaderedItemsControl.Header>
</HeaderedItemsControl>
John Bowen
No, I want a reusable control that has some of its own children and provides a container for adding more children when it's used. Mentioning Expander and having a header was just a very simplified example.
JoeCoder
Did you try this code? If it doesn't do what you want could you provide some more details? I'm aware you don't want an Expander but was trying to provide some context for what a HeaderedItemsControl is.
John Bowen
I found this (http://social.msdn.microsoft.com/forums/en-US/wpf/thread/48a02a96-93d5-4d5a-bf06-53917be73a52/) which I was able to reduce down to exactly what I needed. Thanks for trying though.I did try the code, but saw that it was limited to only providing a custom header. I needed something similar to a TreeItem with a slider, textbox, some images and a rather custom layout.
JoeCoder