2010-09-30 104 views
2

當我使用的是GridSplitter調整大小在網格單元格但其行爲是不是我期待,我無法找到一個解決成長。它是一個由三行組成的網格,第一行的行定義設置爲「自動」幷包含一些元素。第二行有一些數據,並有一個*的行定義來填充剩餘的空間。最後一行是需要調整大小的狀態欄,其中包含一個網格分隔線,並且Auto和MinHeight的行定義高度爲30.拖動GridSplitter導致電池使用自動高度/寬度

問題是當您將GridSplitter一直拖到頂部,它會使細胞溢出。我希望它一旦到達頂端就停下來。希望的行爲可以通過從最後一行刪除Height = Auto來實現,但是這使得底部單元與中間行擴展到相同高度。

這裏是一個XAML墊的例子。

<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:sys="clr-namespace:System;assembly=mscorlib" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" > 
    <Grid ShowGridLines="True"> 
     <Grid.RowDefinitions> 
      <RowDefinition Height="Auto" /> 
      <RowDefinition Height="*" MinHeight="20" /> 
      <RowDefinition Height="Auto" MinHeight="30" /> 
     </Grid.RowDefinitions> 
     <TextBlock Grid.Row="0" Text="Foo" /> 
     <TextBlock Grid.Row="1" Text="Bar" /> 
     <GridSplitter Canvas.ZIndex="1" VerticalAlignment="Top" Grid.Row="2" Background="Cyan" Height="5" HorizontalAlignment="Stretch" /> 
     <TextBlock VerticalAlignment="Bottom" Grid.Row="2" TextWrapping="Wrap">LOL<LineBreak/>LOL<LineBreak/>LOL</TextBlock> 
    </Grid> 
</Page> 

當您拖動到頂部時,您會注意到底部文本消失。

我曾嘗試過各種東西,比如把電網分離器在它自己的小區,並結合高度到另一個物體的ActualHeight等,但沒有真正的工作那麼好。

我知道這是不是最很好解釋的問題,但任何想法將不勝感激。

編輯: 我所做的GridSplitter有自己的行作爲貼在下面,但正如我前面提到的問題仍然存在。我在這裏也設置了ResizeBehavior和ResizeDirection。

<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:sys="clr-namespace:System;assembly=mscorlib" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" > 
    <Grid ShowGridLines="True"> 
     <Grid.RowDefinitions> 
      <RowDefinition Height="Auto" /> 
      <RowDefinition Height="*" MinHeight="20" /> 
      <RowDefinition Height="Auto" /> 
      <RowDefinition Height="Auto" MinHeight="30" /> 
     </Grid.RowDefinitions> 
     <TextBlock Grid.Row="0" Text="Foo" /> 
     <TextBlock Grid.Row="1" Text="Bar" /> 
     <GridSplitter ResizeDirection="Rows" ResizeBehavior="PreviousAndNext" Grid.Row="2" Background="Cyan" Height="5" HorizontalAlignment="Stretch" /> 
     <TextBlock VerticalAlignment="Bottom" Grid.Row="3" TextWrapping="Wrap">LOL<LineBreak/>LOL<LineBreak/>LOL</TextBlock> 
    </Grid> 
</Page> 

什麼不工作是去掉最後行高度=「自動」,將其更改爲一個例子*但是,像這樣

這讓最後一排的大小等於在它之前的行而不是所請求的單元格的大小。

回答

3

GridSplitter應位於其自己的行或列。試驗GridSplitter.ResizeDirectionGridSplitter.ResizeBehavior屬性。

在下面的文章請看:

UPDATE

您可以提供 「明星系數」 來GridLength對象。例如:

<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:sys="clr-namespace:System;assembly=mscorlib" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> 
    <Grid ShowGridLines="True"> 
     <Grid.RowDefinitions> 
      <RowDefinition Height="Auto" /> 
      <RowDefinition Height="95*" MinHeight="20" /> <!--here we are using 95*--> 
      <RowDefinition Height="Auto" /> 
      <RowDefinition Height="5*" MinHeight="30"/> <!--and here we are using 5*-->  
     </Grid.RowDefinitions> 
     <TextBlock Grid.Row="0" Text="Foo" /> 
     <TextBlock Grid.Row="1" Text="Bar" /> 
     <GridSplitter ResizeDirection="Rows" Grid.Row="2" Background="Cyan" Height="5" HorizontalAlignment="Stretch" /> 
     <TextBlock VerticalAlignment="Bottom" Grid.Row="3" TextWrapping="Wrap">LOL<LineBreak/>LOL<LineBreak/>LOL</TextBlock> 
    </Grid> 
</Page> 

所以我們的佈局,需要在不GridSplitter不清楚的行爲。

+0

感謝您的及時回覆。我已經閱讀了您發佈的兩篇文章,並注意到他們表示,只要網格分隔符可見(它是),它就可以佔用與其他元素相同的行。不幸的是,即使在它自己的行中,它仍然有同樣的問題。我已經使用XAML爲GridSplitter行更新了這個問題。我試圖使用ResizeDirection和ResizeBehavior的所有選項,我知道它控制調整哪些網格元素,但行高仍然會出現溢出。 – Seravy 2010-09-30 08:32:07

+0

請參閱更新。 – 2010-09-30 10:49:44

+0

是的,如前所述,*不會導致高度超過延長。我的同事和我花了一些時間把這個問題搞清楚了。當分離器用於自動行定義時,它會將其更改爲絕對GridLength,這是問題所在。因爲它們是絕對的,所以網格分離器無法繼續擴展單元是沒有道理的。 – Seravy 2010-09-30 11:23:00

1

討厭鬼,打我給它。我不妨發佈我的。你的問題在第三行定義中。當你開始向上滾動並且文本消失時,行的高度不斷增加。如果Eugene的解決方案無效,您可以嘗試將最大高度設置爲某種限制。