我的演示应用程序显示两个矩形,应该填满整个浏览器的屏幕。它们之间有一个垂直分离器。这看起来像一个基本场景,但我不知道如何在xaml中实现它。我不能强迫它填满整个屏幕,当移动分割器时,整个屏幕都会增长。有人可以帮忙吗?
<UserControl
xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
x:Class="SilverlightApplication1.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480">
<Grid x:Name="LayoutRoot" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Border BorderBrush="Black" BorderThickness="1" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" MinWidth="50">
</Border>
<controls:GridSplitter Grid.Column="1" VerticalAlignment="Stretch" Width="Auto" ></controls:GridSplitter>
<Border BorderBrush="Blue" BorderThickness="1" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Grid.Column="2" MinWidth="50"></Border>
</Grid>
</UserControl>
答案 0 :(得分:2)
这是您的列布局。左侧和右侧列需要星形大小,中间需要自动调整:
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
击> <击> 撞击>
修改强>
使用网格分割器(在此特定情况下)的正确方法似乎是在网格中仅使用两列。然后应将网格分割器放在第一个列中,但与右侧对齐。像这样:
<Grid x:Name="LayoutRoot"
VerticalAlignment="Stretch"
HorizontalAlignment="Stretch">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Border BorderBrush="Black"
BorderThickness="3"
Margin="3,3,13,3"
VerticalAlignment="Stretch"
HorizontalAlignment="Stretch"
MinWidth="50">
</Border>
<controls:GridSplitter Grid.Column="0"
VerticalAlignment="Stretch"
HorizontalAlignment="Right"
Width="10"></controls:GridSplitter>
<Border BorderBrush="Blue"
Margin="3"
BorderThickness="3"
VerticalAlignment="Stretch"
HorizontalAlignment="Stretch"
Grid.Column="2"
MinWidth="50"></Border>
</Grid>
答案 1 :(得分:2)
GridSplitter很糟糕。尝试对接控制。
答案 2 :(得分:1)
我发现拆分器和自动宽度不起作用。
答案 3 :(得分:1)
这是一个带有silverlight示例的有趣示例页面。
http://www.xs4all.nl/~wrb/Articles/Article_WPFSplitPanels_01_SL.htm