为什么子网格不能扩展以填充父网格宽度?

时间:2010-09-21 04:28:07

标签: silverlight grid width

我定位的网格是背景颜色为azure的网格:

不知何故它没有达到LayoutRoot的全宽,并且以编程方式设置它的宽度将导致布局循环异常。我也尝试将宽度绑定到父布局......但这似乎也不起作用:(

<Border Style="{StaticResource ZoomBorderStyle}">
        <Grid x:Name="LayoutRoot">

            <Grid.RowDefinitions>
                <RowDefinition Height="37"/>
                <RowDefinition Height="76"/>
                <RowDefinition/>
            </Grid.RowDefinitions>

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

            <localView:ViewerMenu Width="Auto" 
                                  ZoomIn="ViewerMenu_ZoomIn" 
                                  ZoomOut="ViewerMenu_ZoomOut" 
                                  LayoutOne="ViewerMenu_One" 
                                  LayoutFour="ViewerMenu_Four" 
                                  ResoFull="ViewerMenu_Full" 
                                  Background="White" />

            <localView:ImageDetails Grid.Row="1" 
                                    ImageMetadata="{Binding CurrentImageContext}" 
                                    VerticalAlignment="Top" 
                                    Height="Auto"
                                    HorizontalAlignment="Stretch"
                                    Width="Auto"/>

            <Grid Grid.Row="1" Grid.RowSpan="2" x:Name="ViewerWrapper" Background="Azure"  
                  HorizontalAlignment="Stretch" 
                  VerticalAlignment="Stretch">


                 <Grid x:Name="QuadPanel" Visibility="Collapsed">
                    <Grid.RowDefinitions>
                        <RowDefinition/>
                        <RowDefinition/>
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition/>
                        <ColumnDefinition/>
                    </Grid.ColumnDefinitions>

                    <zoomControls:QuadPanelImage x:Name="QuadImageTopLeft" Content="{Binding ImageTopLeft}" Margin="15" Grid.Row="0" 
                                                 Grid.Column="0" 
                                                 PanelPosition="TopLeft" 
                                                 MouseLeftDoubleClick="InciteContentControl_MouseLeftDoubleClick"  
                                                 HorizontalContentAlignment="Center"/>
                    <zoomControls:QuadPanelImage x:Name="QuadImageTopRight" Content="{Binding ImageTopRight}" Margin="15" Grid.Row="0" 
                                                 Grid.Column="1" 
                                                 PanelPosition="TopRight" 
                                                 MouseLeftDoubleClick="InciteContentControl_MouseLeftDoubleClick" 
                                                 HorizontalContentAlignment="Center"/>
                    <zoomControls:QuadPanelImage x:Name="QuadImageBottomLeft" Content="{Binding ImageBottomLeft}" Margin="15" Grid.Row="1" 
                                                 Grid.Column="0" 
                                                 PanelPosition="BottomLeft" 
                                                 MouseLeftDoubleClick="InciteContentControl_MouseLeftDoubleClick" 
                                                 HorizontalContentAlignment="Center"/>
                    <zoomControls:QuadPanelImage x:Name="QuadImageBottomRight" Content="{Binding ImageBottomRight}" Margin="15" Grid.Row="1"
                                                 Grid.Column="1" 
                                                 PanelPosition="BottomRight" 
                                                 MouseLeftDoubleClick="InciteContentControl_MouseLeftDoubleClick" 
                                                 HorizontalContentAlignment="Center"/>
                </Grid>

2 个答案:

答案 0 :(得分:1)

您的布局根位于边框内。边框的默认行为是适合其内容。您尚未提供ZoomBorderStyle样式XAML,因此不确定是否存在干扰。

尝试将Horizo​​ntalAlignment =“Stretch”添加到顶级边框(或删除样式或边框本身作为测试)。

如果这没有帮助,请提供更多详细信息/ Xaml。如果可能的话,将问题减少到可以在没有所有额外控制引用的情况下使用的独立测试。

答案 1 :(得分:0)

在删除所有边框并将拉伸设置为所有容器后,仍然不知道为什么网格不会扩展以填充应用程序宽度。无论如何..我找到了一个不会引发layoutrecycle异常错误的解决方案:

而不是这个(当我非常快地调整大小时抛出异常)

void ZoomDocViewer_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            QuadPanel.Height = e.NewSize.Height;
            QuadPanel.Width= e.NewSize.Height;
        }

我从应用程序获取宽度:

 void ZoomDocViewer_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            QuadPanel.Width = Application.Current.Host.Content.ActualWidth; 
        }

哪个不会抛出异常!