Set grid to 75% of parent grid using WPF

Total Post:29

Points:203
WPF 
WPF
 2858  View(s)
Ratings:
Rate this:
<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.
 </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>

I am displaying a Text in
a Grid, but I want its max width
to be set equals to the 75% of its parent grid. Thanks!

  1. Post:70

    Points:494
    Re: Set grid to 75% of parent grid using WPF

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

    Put your target grid in the first column of the wrapper grid and now it will have 75% width of it's parent.

      Modified On Apr-03-2018 05:00:31 AM

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!