2014-03-27 33 views
0

我想將itemcontrol的高度設置爲網格行定義中定義的值。如果我手動設置itemscontrol上的高度,它當然會影響控件。我如何綁定或實現此行爲?我只想讓我的itemscontrol尺寸由網格確定。謝謝!ItemsControl Height Issue

<ScrollViewer> 

     <Grid> 
      <Grid.RowDefinitions> 
       <RowDefinition Height="600"/> 
       <RowDefinition Height="500"/> 
      </Grid.RowDefinitions> 

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

      <ItemsControl Grid.Row="1" Grid.Column="0" Name="MIPRegion" cal:RegionManager.RegionName="MIPRegion" /> 

     </Grid> 
    </ScrollViewer> 
+0

問題是什麼? ItemsControl在您的示例中正確具有500像素的高度。 –

+0

也許你的意思是scrollviewer的高度爲500? –

回答

1

您可以綁定到RowDefinition的ActualHeight屬性。

<ScrollViewer> 

    <Grid> 
     <Grid.RowDefinitions> 
      <RowDefinition x:Name="rowDef0" Height="600"/> 
      <RowDefinition x:Name="rowDef1" Height="500"/> 
     </Grid.RowDefinitions> 

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

     <ItemsControl Height="{Binding Path=ActualHeight, ElementName=rowDef1}" 
         Grid.Row="1" Grid.Column="0" Name="MIPRegion" 
         cal:RegionManager.RegionName="MIPRegion" /> 

    </Grid> 
</ScrollViewer> 
1

試試這個

我還沒有使用的ActualHeight和ActualWidth的用於寬度和高度本身就是類型GridLength的結合。

<ScrollViewer> 
    <Grid> 
     <Grid.RowDefinitions> 
      <RowDefinition Height="600"/> 
      <RowDefinition x:Name="RowHeight" Height="500"/> 
     </Grid.RowDefinitions> 
     <Grid.ColumnDefinitions> 
      <ColumnDefinition Width="*" x:Name="ColumnWidth"/> 
     </Grid.ColumnDefinitions> 
     <ItemsControl Grid.Row="1" Background="Green" Width="{Binding ElementName=ColumnWidth,Path=Width}" Height="{Binding ElementName=RowHeight,Path=Height}" Grid.Column="0" Name="MIPRegion" >    
     </ItemsControl> 
    </Grid> 
    </ScrollViewer> 
+0

我認爲最好綁定到ActualHeight和ActualWidth屬性。另外,OP只需要綁定高度。 – qqbenq

+0

actualheight和實際寬度在我的情況下不起作用。 –

0

在我的情況RowDefinition的高度爲*,它只有當我綁定的ItemsControl.Height的高度,而不是針對的ActualHeight工作。然後我意識到double和GridLenght之間的這種綁定是不正確的。 (由BindingExpression生成的值對於目標屬性無效; Value ='*'BindingExpression:Path = Height;)但是我仍然確認,在某些情況下,綁定到ActualHeight時沒有按預期工作。