0

我不知道如何在WPF. 这是我的代码:

<ScrollViewer Grid.Row="2">
    <Grid>
        <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
    </Grid.RowDefinitions>

        <Grid Grid.Row="0" HorizontalAlignment="Left" Margin="10,5,0,0" Width="500">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>

            <Grid Grid.Row="0">
                <Grid.Background >
                    <ImageBrush ImageSource="Public\Images\chat_green-textarea.png"/>
                </Grid.Background>

                <TextBlock Padding="5" Foreground="White" FontSize="15" TextWrapping="Wrap">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</TextBlock>                                    
            </Grid>

            <Grid Grid.Row ="1">
                <Image Source="Public\Images\chat_green-textarea-tail.png" Height="20" Width="30" HorizontalAlignment="Left" Margin="10,-4,0,0"/>
            </Grid>
        </Grid>
    </Grid>
</ScrollViewer>

我在 aText中显示 a Grid,但我希望将其最大宽度设置为等于其父网格的 75%。谢谢!

4

1 回答 1

1

将另一个带有两列的网格放入其中,其中包含列定义

<ScrollViewer>
    <Grid>
        <Grid.ColumnDefinitions>
            <columndefinition Width="3*"/>
            <columndefintiion Width="1*"/>
        </Grid.ColumnDefinitions>

        <Grid Grid.Column="0">
            ... <snip> ...
        </Grid>
    </Grid>
</ScrollViewer>

将您的目标网格放在包装网格的第一列,现在它将具有其父级的 75% 宽度。

于 2013-05-27T08:38:08.867 回答