2014-02-25 12 views
0

我有下面的代碼,我把一個ScrollViewer放在第1行,按鈕和文本放在其他行。第一行(第0行)正確顯示,但ScrollViewer會佔用屏幕的其餘部分。以下行中的按鈕被從屏幕上推出並且不可見。如果我爲ScrollViewer硬編碼高度,它可以正常工作,但我不想這樣做。看來我的GridUnitType.Star命令被忽略。我錯過了什麼?RowDefinition GridUnitType.Star被忽略

Grid mainGrid = new Grid(); 
mainGrid.VerticalAlignment = VerticalAlignment.Stretch; 
mainGrid.HorizontalAlignment = HorizontalAlignment.Stretch; 
mainGrid.ColumnDefinitions.Add(new ColumnDefinition()); 
for (int i = 0; i < 6; i++) 
{ 
    RowDefinition r = new RowDefinition(); 
    if (i == 1) // scrollview = 1 
    { 
     r.Height = new GridLength(1, GridUnitType.Star); // take 100% of the remaining height 
     //r = new RowDefinition { Height = new GridLength(300) }; 
    } 
    else 
    { 
     r.Height = new GridLength(0, GridUnitType.Auto); // wrap the height 
    } 
    mainGrid.RowDefinitions.Add(r); 
} 
+0

嘗試在ScrollViewer中設置「VerticalScrollBarVisibility =」Auto「」? – har07

+0

我已經這樣做了。 – user1390106

回答

0

它今天按預期工作。我想退出並重新啓動Visual Studio必須重置一些東西。