2014-01-26 53 views
0

首先,我是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

關於你的第二個問題,Swtting的Expander.VerticalAlignment爲Stretch會做的伎倆。

至於你的第一個問題。 Expander控件從HeaderedContentControl繼承,這意味着它具有可以自定義的Header屬性。 您可以通過將HeaderTemplate設置爲僅顯示前兩個元素的另一個列表框來完成此操作。

Similar question in Stack overflow

+0

嗨,謝謝你的回覆。我試着設置VerticalAlignment和VerticalContentAlignment來伸展,但擴展器不能伸展到全屏高度。它不會高於我在屏幕中央的ContentControl底部。屏幕的左側,右側和頂部也有停靠面板。 – user1698316

+0

也許你可以在這裏發佈你的完整xaml,這樣我就可以更好地分離它。 –

+0

上面按照要求貼滿了xaml。非常感謝。注意:B1_Click位於後面的代碼中,它只是在右側停靠面板中隱藏或顯示擴展器。 – user1698316