2011-04-27 28 views
0

我在另一個網格的第一列中有一個網格,並且希望內部網格的行具有與父網格的行相同的高度。這個想法是,內部網格可以包含我希望能夠隱藏的描述(但保持與父網格的行對齊,因爲這些描述與父網格中的特定問題相關聯)。一個WPF ColumnDefinition不具有可視性財產:(自動調整另一個網格中包含的網格的行的大小

的代碼我有thusfar:

<Grid ShowGridLines="true" Name="gridje"> 
    <Grid.RowDefinitions> 
     <RowDefinition Height="Auto" Name="row0"/> 
     <RowDefinition Height="Auto" Name="row1"/> 
     <RowDefinition Height="Auto" Name="row2"/> 
    </Grid.RowDefinitions> 
    <Grid.ColumnDefinitions> 
     <ColumnDefinition /> 
     <ColumnDefinition /> 
    </Grid.ColumnDefinitions> 
    <Grid Grid.Row="0" Grid.RowSpan="3" ShowGridLines="true"> 
     <Grid.RowDefinitions> 
      <RowDefinition Height="{Binding ElementName=row0, Path=ActualHeight, Mode=OneWay}"/> 
      <RowDefinition Height="{Binding ElementName=row1, Path=ActualHeight, Mode=OneWay}"/> 
      <RowDefinition Height="{Binding ElementName=row2, Path=ActualHeight, Mode=OneWay}"/> 
     </Grid.RowDefinitions> 
     <TextBlock Grid.Row="0">Joepie</TextBlock> 
     <TextBlock Grid.Row="2">Joepie</TextBlock> 
    </Grid> 
    <TextBlock Grid.Row="0" Grid.Column="1" TextWrapping="WrapWithOverflow">Klaasje daskljf askldfas dfasjkl dfhklasjdfh askljdfh askljdfh h askljdfh klasdfh alsjkdfh askldfh askljfh alsdjkfh asklfh </TextBlock> 
    <TextBlock Grid.Row="1" Grid.Column="1" TextWrapping="WrapWithOverflow">Klaasje daskljf askldfas dfasjkl dfhklasjdfh askljdfh askljdfh h askljdfh klasdfh alsjkdfh askldfh askljfh alsdjkfh asklfh</TextBlock> 
    <TextBlock Name="textb" Grid.Row="2" Grid.Column="1" TextWrapping="WrapWithOverflow" Text="{Binding ElementName=row0, Path=ActualHeight, Mode=OneWay}"></TextBlock> 
    <Button Content="Button" Grid.Column="1" Grid.Row="2" Height="23" HorizontalAlignment="Left" Margin="66,173,0,0" Name="button1" VerticalAlignment="Top" Width="75" Click="button1_Click" /> 
</Grid> 

奇怪的是,在VS2010設計模式,一切工作正常,但一旦所有正在運行的實際高度性能留爲零。

任何幫助,將不勝感激。也許使用一些其他WPF控件來完成這也是沒有問題的。

回答

2

也許Grid.IsSharedSizeScope - 屬性會幫助你。有了這個,你可以同步使網格元素的寬度和高度增加。 有關如何使用它的示例包含在msdn文章中。

+0

我會試一試。而且:如何在第一列中使用一個網格並將其大小設置爲零。我在開車的時候想到了這款車);但是不知道我是否已經嘗試過...... – 2011-04-27 16:41:43

+0

將尺寸設置爲零會導致右側顯示非常小的滾動條,因爲它仍會嘗試顯示內容「隱藏」欄......所以這不是一個選項。 – 2011-04-28 07:54:31

+1

@Joep Greuter:不知道我是否理解你的問題是正確的,但爲何不在第一列中插入信息文本塊,將第一列的widht設置爲「Auto」,然後相應地隱藏/顯示信息文本塊捆綁)。如果我理解你的問題是正確的,這將按照你的意願行事。然後,您還可以擺脫子網格,使設計更容易。順便說一下,我已經讀過綁定到Active [Width | Height]會減慢佈局性能。不知道這是否是一個事實,但我可以想象。因此我會在投入生產之前做一些測試。 – HCL 2011-04-28 08:03:46

相關問題