0
我与此类似下面的示例XAML定义布局的WPF应用程序的工作:如何让ItemsControl适合其内容,而不是垂直扩展而不考虑它的兄弟元素?
<Window>
<Grid x:Name="LayoutRoot">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="5*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Border Grid.Column="0" Background="AliceBlue" />
<!-- Main Panel -->
<Grid Grid.Column="1"
Background="LightPink">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<!-- Row 0: some User Control -->
<Grid Grid.Row="0" MinHeight="100" />
<!-- Row 1: some label -->
<Label Grid.Row="1" Content="Example text" />
<!-- Row 2: another User Control -->
<StackPanel Grid.Row="2">
<ScrollViewer VerticalScrollBarVisibility="Auto">
<ItemsControl>
<ItemsControl.Items>
<ContentPresenter Content="Item 1" />
<ContentPresenter Content="Item 2" />
<ContentPresenter Content="Item 3" />
<ContentPresenter Content="Item 4" />
<ContentPresenter Content="Item 5" />
<ContentPresenter Content="Item 6" />
</ItemsControl.Items>
</ItemsControl>
</ScrollViewer>
<Button Content="Open" />
</StackPanel>
</Grid>
<Border Grid.Column="2" Background="AliceBlue" />
</Grid>
</Window>
简而言之,布局根是一个包含3列的网格;左边和右边的列只是间隔符,中间的列包含2个用户控件(在我上面的例子中用2个网格表示)。
我想实现如下:
如果有足够的垂直空间,我想ItemsControl的显示没有滚动条和按钮,出现正下方的物品(不其包含面板的底部)。
如果没有足够的垂直空间,我希望ItemsControl显示一个滚动条而不是垂直有效地将按钮踢出视图。
一切我试图似乎之一:
- 保持停靠至底部时打开按钮有足够的空间,或者
- 当由于ItemsControl垂直扩展而导致空间不足时,将Open按钮踢出视图。
有什么方法可以实现所需的布局(无论是在XAML还是代码中)?
不会因为工作。 –
@ AhmedA.Hamid事实并非如此。抱怨之前,你应该简单地尝试一下。 – Clemens
试过了。它不会将Open按钮踢出显示屏,但是如果有足够的空间,它将按钮保持在底部,这不是我想要达到的目的(查看问题中的视觉插图)。 –