WPF Expander in Xaml?
I want to make an ItemsControl
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.
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">
<!-- Tes开发者_如何学Pythont 1 and Test 2 should go here. -->
</StackPanel>
</StackPanel>
</ItemsControl>
Main.xaml:
<controls:LayerPanelItem>
<TextBlock>Test 1</TextBlock>
<TextBlock>Test 2</TextBlock>
</controls:LayerPanelItem>
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">
<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>
精彩评论