我有一个托管 2 个较小网格的父网格(“输出”)。
较小的网格 MainDisplay(它基本上在 ViewBox 中显示一个图像,我想占据除 2 个子网格中的另一个中的 300 之外的所有水平空间)和 Input(固定宽度为 300,实际上按预期工作) .
我的问题是:
1)父网格不消耗所有水平空间。我希望额外的空间与 ViewBox 一起进入网格。
我已经洒了 'HorizontalAlignment="Stretch"' 和 'Width="*"' ,但它不会占用屏幕上的所有空间!
2)我有代码来获取图像的宽度/高度。除非我明确设置高度、宽度,否则后面的代码会尝试获取高度和宽度并崩溃……但如果我明确设置宽度/高度,恐怕它不会占用可用空间。
这是代码:
<Grid x:Name="Output" Background="#1D1D1D" Margin="0,2,0,-2" HorizontalAlignment="Stretch">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="300"/>
</Grid.ColumnDefinitions>
<Grid x:Name="MainDisplay" HorizontalAlignment="Stretch" VerticalAlignment="Top" Grid.Column="0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Viewbox Width="Auto" Height="Auto" MinWidth="400" MinHeight="400" x:Name="Scenario4ImageContainer" Stretch="Uniform">
<Image x:Name="Scenario4Image" PointerPressed="Scenario4Image_PointerPressed" HorizontalAlignment="Stretch" />
</Viewbox>
</Grid>
<Grid Width="300" x:Name="Input" Grid.Column="1">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<StackPanel Grid.Row="0">
<TextBlock Style="{StaticResource BasicTextStyle}" TextWrapping="Wrap"
Text="Tools" />
<Grid Margin="0,10,0,0">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="230" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Button Grid.Row="0" Grid.Column="0" HorizontalAlignment="Stretch" Background="DarkSlateGray"
Content="Draw Mandelbrot set" Click="DrawMandelbrotSet_Click" />
<TextBlock x:Name="Scenario4DrawMandelbrotDescription" Grid.Row="0" Grid.Column="1"
Style="{StaticResource BasicTextStyle}" TextWrapping="Wrap" VerticalAlignment="Center"
Text="Text." />
<Button x:Name="Scenario4SetSourceButton" Grid.Row="1" Grid.Column="0" HorizontalAlignment="Stretch"
Content="Load image using SetSource" Click="LoadImageUsingSetSource_Click" />
<TextBlock x:Name="Scenario4SetSourceDescription" Grid.Row="1" Grid.Column="1"
Style="{StaticResource BasicTextStyle}" TextWrapping="Wrap" VerticalAlignment="Center"
Text="Text." />
<Button x:Name="Scenario4LoadImageButton" Grid.Row="2" Grid.Column="0" HorizontalAlignment="Stretch"
Content="Load image using PixelBuffer" Click="LoadImageUsingPixelBuffer_Click" />
<TextBlock x:Name="Scenario4LoadImageDescription" Grid.Row="2" Grid.Column="1"
Style="{StaticResource BasicTextStyle}" TextWrapping="Wrap" VerticalAlignment="Center"
Text="Text." />
</Grid>
</StackPanel>
</Grid>