0
有沒有比我發現引用嵌入網格的構建網格列的寬度更優雅的方法?我不能以更好的方式訪問特定網格列的實際寬度嗎?我是否也可以有雙向連接,以便如果子網格中的列變得太寬,父級中的列會增長以適應內容?網格列的WPF參考寬度
<Page
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto" />
<ColumnDefinition Width="0.5*" />
<ColumnDefinition Width="auto" />
<ColumnDefinition Width="0.5*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="26" />
<RowDefinition Height="26" />
</Grid.RowDefinitions>
<Label Grid.Row="0" Grid.Column="0" x:Name="col0" Content="This"/>
<Label Grid.Row="0" Grid.Column="1" x:Name="col1" Content="is"/>
<Label Grid.Row="0" Grid.Column="2" x:Name="col2" Content="a"/>
<Label Grid.Row="0" Grid.Column="3" x:Name="col3" Content="test."/>
<Grid Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="{Binding Path=ActualWidth, ElementName=col0}" />
<ColumnDefinition Width="{Binding Path=ActualWidth, ElementName=col1}" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition />
</Grid.RowDefinitions>
<Label Grid.Row="0" Grid.Column="0" VerticalAlignment="Center" Content="The" />
<Label Grid.Row="0" Grid.Column="1" VerticalAlignment="Center" Content="same width" />
</Grid>
</Grid>
</Page>