Xaml中的WPF扩展器?

时间:2010-02-18 00:28:01

标签: wpf expander

我想创建一个ItemsControl,它提供一些自己的子项,然后在使用时可以添加其他子项,类似于内置的Expander类。

但是,在此示例中,Header T extBlock也已删除。这是一个改述 问题I asked yesterday

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">

    <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>

1 个答案:

答案 0 :(得分:0)

如果我正确理解你,你需要更多的HeaderedItemsControlExpander来自HeaderedContentControl,这会将ItemsControl行为添加到:

<HeaderedItemsControl x:Class="WpfApplication1.LayerPanelItem"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <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>