2010-06-16 69 views
0

我正在處理一個複雜的應用程序,並且我遇到了一個列表框不受窗口高度限制的問題。這是它的外觀的簡化版本。我怎樣才能讓這個列表框正確地被窗口限制?現在,底部滾動按鈕離開屏幕,直到窗口足夠大以適合整個列表框時才能看到。我需要找到一個解決方案,使列表框始終有界,因爲我必須通過ScaleTransform實現縮放。WPF列表框是無界的窗口

<Grid>   
    <Grid.ColumnDefinitions> 
     <ColumnDefinition Width="300" /> 
     <ColumnDefinition/> 
    </Grid.ColumnDefinitions> 
     <Grid Name="stack"> 
      <Grid.LayoutTransform> 
       <ScaleTransform 
       ScaleX="{Binding ElementName=slider, Path=Value}" 
       ScaleY="{Binding ElementName=slider, Path=Value}" /> 
      </Grid.LayoutTransform> 
      <WrapPanel HorizontalAlignment="Left"> 
       <Expander IsExpanded="False" Width="300">hey</Expander> 
       <Expander IsExpanded="True" VerticalAlignment="Stretch" ClipToBounds="True"> 
        <Grid>        
         <ListBox >        
          <Button>hey</Button> 
          <!-- just add a lot more of these to see the problem --> 
          <Button>hey</Button> 
         </ListBox> 
        </Grid> 
       </Expander> 
      </WrapPanel> 

     </Grid> 
    <Slider Grid.Column="1" Name="slider" Minimum="1" Maximum="4" Value="1" /> 

</Grid> 

回答

1

試試下面的代碼:

<Grid> 
    <Grid.RowDefinitions> 
     <RowDefinition Height="*" /> 
     <RowDefinition Height="Auto" /> 
    </Grid.RowDefinitions> 
    <Border Grid.Row="0"> 
     <Grid Name="stack"> 
      <Grid.LayoutTransform> 
       <ScaleTransform ScaleX="{Binding ElementName=slider, Path=Value}" 
           ScaleY="{Binding ElementName=slider, Path=Value}" /> 
      </Grid.LayoutTransform> 
      <Grid> 
       <Grid.RowDefinitions> 
        <RowDefinition Height="Auto" /> 
        <RowDefinition Height="*" /> 
       </Grid.RowDefinitions> 
       <Border Grid.Row="0"> 
        <Expander IsExpanded="False" 
           Width="300">hey</Expander> 
       </Border> 
       <Border Grid.Row="1"> 
        <Expander IsExpanded="True" 
           VerticalAlignment="Stretch" 
           ClipToBounds="True"> 
         <Grid> 
          <ListBox> 
           <Button>hey</Button> 
           <Button>hey</Button> 
           <Button>hey</Button> 
           <Button>hey</Button> 
           <Button>hey</Button> 
           <Button>hey</Button> 
           <!-- just add a lot more of these to see the problem --> 
           <Button>hey</Button> 
          </ListBox> 
         </Grid> 
        </Expander> 
       </Border> 
      </Grid> 
     </Grid> 
    </Border> 
    <Border Grid.Row="1"> 
     <Slider Name="slider" 
       Minimum="1" 
       Maximum="4" 
       Value="1" /> 
    </Border> 
</Grid> 
+0

這不正是我想要的。謝謝! – wangburger 2010-06-16 14:28:13