【问题标题】:Stretching Grid inside another Grid在另一个网格内拉伸网格
【发布时间】:2013-11-06 21:05:32
【问题描述】:

如何水平拉伸“SecondGrid”?

<Window x:Class="WpfApplication2.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="350" Width="525">
<Grid VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="*"/>
        <ColumnDefinition Width="Auto"/>
        <ColumnDefinition Width="*"/>
    </Grid.ColumnDefinitions>
    <Label Content="Left" Grid.Column="0" />
    <GridSplitter HorizontalAlignment="Right" 
              VerticalAlignment="Stretch" 
              Grid.Column="1" ResizeBehavior="PreviousAndNext"
              Width="5" Background="#FFBCBCBC"/>
    <Label Content="Righkk" Grid.Column="2" Margin="5,0,-5,0" />


    <Grid Name="SecondGrid" Grid.Column="2" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="*"  />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>

        <GridSplitter 
        ResizeDirection="Rows"            
        Grid.Row="1"
        Width="Auto" 
        Height="3"
       Background="#FFBCBCBC"
        HorizontalAlignment="Stretch" 
        />
        <ListBox HorizontalAlignment="Stretch"  VerticalAlignment="Stretch" Grid.Row="0"/>
        <WebBrowser  Grid.Row="2" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
        <Label Content="Right" Grid.Row="2" />
    </Grid>


    <StackPanel HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
        <ToolBarTray DockPanel.Dock="Top">
            <ToolBar>
                <Button Command="New" Content="New" />
                <Button Command="Open" Content="Open" />
                <Button Command="Save" Content="Save" />
            </ToolBar>
        </ToolBarTray>
        <TreeView>
            <TreeViewItem Header="Level 1" IsExpanded="True">
                <TreeViewItem Header="Level 2.1" />
                <TreeViewItem Header="Level 2.2" IsExpanded="True">
                    <TreeViewItem Header="Level 3.1" />
                    <TreeViewItem Header="Level 3.2" />
                </TreeViewItem>
                <TreeViewItem Header="Level 2.3" />
            </TreeViewItem>
        </TreeView>
    </StackPanel>

</Grid>

【问题讨论】:

  • 我试过你的代码,SecondGrid 似乎在垂直拉伸。也许您可以发布您所看到的图片并说明您的期望。
  • 是的,第二个网格垂直拉伸,至少在我这边也是这样。也许您打算扩展其他控制并且在视觉上您没有正确解释事物。您可以随时为第二个网格背景着色,以便更好地了解元素。
  • 我的意思是横向的,抱歉。
  • 从我昨天使用的示例中回忆起,水平方向它也在拉伸,所以可能具有预期布局的图像会有所帮助,但我会尽快再次检查它

标签: c# wpf grid-layout


【解决方案1】:

我只需要删除

<Grid.ColumnDefinitions>
  <ColumnDefinition Width="*" />
  <ColumnDefinition Width="Auto" />
  <ColumnDefinition Width="*"  />
</Grid.ColumnDefinitions>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-11-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多