2010-09-21 57 views
0

我想要的網格是背景色爲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> 

回答

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; 
     } 

哪個不會拋出異常!

1

您的佈局根是一個邊框內。邊框的默認行爲是適應其你沒有提供ZoomBorderStyle風格的XAML,所以不知道它是否會干擾

嘗試在頂層邊框(或刪除樣式或邊框本身作爲測試)中添加Horizo​​ntalAlignment =「Stretch」。

如果這沒有幫助,請提供更多詳細信息/ Xaml。如果可能,請將問題簡化爲獨立測試可以在沒有所有額外控制參考的情況下使用。

+0

謝謝!我會給它一個去看看它是否是邊界干擾。 – bcm 2010-09-21 08:59:20

+0

我嘗試刪除邊框或向邊框添加拉伸,兩者都不起作用。 LayoutRoot網格根據內容擴展或縮小,即使對於水平和垂直也是如此。 – bcm 2010-09-21 22:26:39