C# XAML宽度设置(以百分比表示)

C# XAML宽度设置(以百分比表示),c#,xaml,width,C#,Xaml,Width,我有以下代码 <Grid Grid.Row="1"> <Grid.ColumnDefinitions> <ColumnDefinition Width="100*" /> <ColumnDefinition Width="100*" /> <ColumnDefinition Width="10

我有以下代码

<Grid Grid.Row="1">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="100*" />
                    <ColumnDefinition Width="100*" />
                    <ColumnDefinition Width="100*" />
                    <ColumnDefinition Width="100*" />
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="100*" />
                    <RowDefinition Height="100*" />
                    <RowDefinition Height="100*" />
                </Grid.RowDefinitions>

                <StackPanel Grid.Row="0" Grid.Column="0" Width="30*">
                    ...
                </StackPanel>
     </Grid>

...

我正在尝试将Stackpanel宽度设置为单元格的30%。我已经推荐了这个职位。根据帖子,它的宽度应该是30*。但它显示了错误“30*字符串无法转换为长度”。所以我想纠正这个错误,或者我只想得到一种方法来设置宽度为单元格30%的stackpanel。谢谢。

堆垛板的宽度只能是一个双人床。网格宽度可以采用*和自动(*如果未指定,则为默认值)

还要注意的是,StackPanel永远不会比内容所需的宽度更大。HorizontalAlignment=“Stretch”无效

我建议你这样做

        <Grid Grid.Row="1">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="100*" />
            <ColumnDefinition Width="100*" />
            <ColumnDefinition Width="100*" />
            <ColumnDefinition Width="100*" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="100*" />
            <RowDefinition Height="100*" />
            <RowDefinition Height="100*" />
        </Grid.RowDefinitions>


        <Grid Grid.Row="0" Grid.Column="0" >
            <Grid.ColumnDefinitions>
                <ColumnDefinition />
                <ColumnDefinition />
                <ColumnDefinition />
            </Grid.ColumnDefinitions>

            <StackPanel>
            </StackPanel>

        </Grid>
    </Grid>

stackpanel的宽度只能是一倍。网格宽度可以采用*和自动(*如果未指定,则为默认值)

还要注意的是,StackPanel永远不会比内容所需的宽度更大。HorizontalAlignment=“Stretch”无效

我建议你这样做

        <Grid Grid.Row="1">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="100*" />
            <ColumnDefinition Width="100*" />
            <ColumnDefinition Width="100*" />
            <ColumnDefinition Width="100*" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="100*" />
            <RowDefinition Height="100*" />
            <RowDefinition Height="100*" />
        </Grid.RowDefinitions>


        <Grid Grid.Row="0" Grid.Column="0" >
            <Grid.ColumnDefinitions>
                <ColumnDefinition />
                <ColumnDefinition />
                <ColumnDefinition />
            </Grid.ColumnDefinitions>

            <StackPanel>
            </StackPanel>

        </Grid>
    </Grid>