首先,我是WPF设计的新手。无论如何,我有一个扩展器,其中包含一个位于窗口底部的列表框。当扩展器最小化时,我希望列表框中的前两个元素可见,但是当它最大化时,我希望它占据整个屏幕高度。我不确定如何解决这个问题,并且非常感谢任何提示。下面是我到目前为止要处理的代码。
<Window x:Class="WPFPlay.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow"
Height="300"
Width="300"
DataContext="{Binding Main, Source={StaticResource Locator}}" SizeToContent="Manual">
<Window.Resources>
<ControlTemplate x:Key="VerticalExpander" TargetType="{x:Type Expander}">
<Border Name="ContentBorder" Width="0">
<ContentPresenter />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsExpanded" Value="True">
<Setter TargetName="ContentBorder" Property="Width" Value="Auto" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
<ControlTemplate x:Key="HorizontalExpander" TargetType="{x:Type Expander}">
<Border Name="ContentBorder" Width="0">
<ContentPresenter />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsExpanded" Value="True">
<Setter TargetName="ContentBorder" Property="Height" Value="Auto" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Window.Resources>
<Grid>
<DockPanel LastChildFill="True">
<Grid DockPanel.Dock="Right">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="20" />
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="1" Orientation="Vertical">
<Button Name="B1" Content="+" Click="B1_Click" />
</StackPanel>
<DockPanel LastChildFill="True">
<Grid Grid.Column="0" DockPanel.Dock="Right" HorizontalAlignment="Right">
<Expander Name="MainExpander1" Template="{StaticResource VerticalExpander}" IsExpanded="False">
<Border CornerRadius="6" BorderBrush="Gray" Background="LightGray" BorderThickness="2">
<StackPanel>
<Label Content="Document1"/>
<Label Content="Document2"/>
<Label Content="Document3"/>
</StackPanel>
</Border>
</Expander>
</Grid>
</DockPanel>
</Grid>
<WrapPanel HorizontalAlignment="Center" DockPanel.Dock="Top">
<TextBlock FontSize="14">
<Bold>
<Run>
Header + Labels etc
</Run>
</Bold>
</TextBlock>
</WrapPanel>
<StackPanel DockPanel.Dock="Bottom">
<Expander VerticalAlignment="Stretch" Name="StatusBarExpander" ExpandDirection="Up" IsExpanded="False">
<StackPanel>
<ListBox>
<ListBoxItem Content="xxxxxxxxxxxxxxxxxxxx" />
<ListBoxItem Content="yyyyyyyyyyyyyyyyyy" />
<ListBoxItem Content="zzzzzzzzzzzzzzzzzzzz" />
</ListBox>
</StackPanel>
</Expander>
</StackPanel>
<StackPanel DockPanel.Dock="Left">
<Button Content="button1"/>
<Button Content="button2"/>
<Button Content="button3"/>
<Button Content="button4"/>
</StackPanel>
<!-- Centre of it all!!!-->
<ContentControl />
</DockPanel>
</Grid>
答案 0 :(得分:0)
至于你的第二个问题,将Expander.VerticalAlignment Swtting to Stretch就可以了。
至于你的第一个问题。 Expander控件继承自HeaderedContentControl,这意味着它具有可以自定义的Header属性。 您可以通过将HeaderTemplate设置为另一个列表框来完成此操作,该列表框仅显示前两个元素。