2010-06-16 68 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