XML网格不会扩展

时间:2013-02-23 02:47:08

标签: winrt-xaml

我有一个托管2个较小网格的父网格(“输出”)。

较小的网格MainDisplay(基本上显示ViewBox中的图像,我想要占用除2个子网格中另外的300个以外的所有水平空间)和Input(固定宽度为300,实际上有效)如预期的那样。)

我的问题是:

1)父网格不消耗所有水平空间。我希望额外的空间与ViewBox一起进入网格。

我已经把'Horizo​​ntalAlignment ='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>

1 个答案:

答案 0 :(得分:1)

我对此并不是100%肯定,但在第一列定义中尝试"*"而不是"Auto"

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