Change the Height of Parent Row

Jassim Al Rahma 1,556 Reputation points
2021-08-15T21:24:41.19+00:00

Hi,

I have the following:

<Grid Grid.Row="11" ColumnSpacing="0" RowSpacing="0">
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto" />
        <RowDefinition Height="Auto" />
        <RowDefinition Height="Auto" />
    </Grid.RowDefinitions>

    <Grid.Triggers>
    <DataTrigger TargetType="Grid" Binding="{Binding Source={x:Reference LabelPostTreatments}, Path=Text, TargetNullValue=''}" Value="">
        <Setter Property="IsVisible" Value="False" />
    </DataTrigger>
    </Grid.Triggers>

    <Label Grid.Row="0" Margin="5" Text="Treatments : " TextColor="Red" VerticalOptions="Center" />
    <Label x:Name="LabelPostTreatments" Grid.Row="1" Margin="5" Text="{Binding post_treatments}" />

    <BoxView Grid.Row="2" HeightRequest="1" BackgroundColor="LightGray" HorizontalOptions="FillAndExpand" />
</Grid>

How can I make the DataTrigger to change the parent row which is in the above Row="11"?

Thanks,
Jassim

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,326 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,648 questions
.NET Runtime
.NET Runtime
.NET: Microsoft Technologies based on the .NET software framework.Runtime: An environment required to run apps that aren't compiled to machine language.
1,141 questions
{count} votes

Accepted answer
  1. JarvanZhang 23,951 Reputation points
    2021-09-01T02:10:07.59+00:00

    but the problem is when you have 10 Rows in the grid were set to Auto and you hide the content of Row 2 to Row9 then you will have a big empty space

    Sorry for the unclear information. The empty space is the row spacing, please set RowSpacing to 0 for the parent grid. The below code could hide the row successfully, please check it. And here is the working gif: https://imgur.com/q0d6pdD

    <Grid RowSpacing="0">
        <Grid.RowDefinitions>
            <RowDefinition x:Name="this_is_the_row" Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
    
        <Grid Grid.Row="0" ColumnSpacing="0" RowSpacing="0" BackgroundColor="LightBlue">
            <Grid.Triggers>
                <DataTrigger TargetType="Grid" Binding="{Binding Source={x:Reference LabelPostGender}, Path=Text, TargetNullValue=''}" Value="testing">
                    <Setter Property="IsVisible" Value="False" />
                </DataTrigger>
            </Grid.Triggers>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
    
            <Label Grid.Row="0" Margin="5" Text="Treatments : " TextColor="Red" VerticalOptions="Center" />
            <Entry x:Name="LabelPostGender" Grid.Row="1" Margin="5" />
    
            <BoxView Grid.Row="2" HeightRequest="1" BackgroundColor="LightGray" HorizontalOptions="FillAndExpand" />
        </Grid>
        <Label Text="the second row" Grid.Row="1"/>
        <BoxView HeightRequest="150" Grid.Row="2" BackgroundColor="Red">
            <BoxView.Triggers>
                <DataTrigger TargetType="BoxView" Binding="{Binding Source={x:Reference LabelPostGender}, Path=Text, TargetNullValue=''}" Value="testing">
                    <Setter Property="HeightRequest" Value="0" />
                </DataTrigger>
            </BoxView.Triggers>
        </BoxView>
        <Label Text="the 4th row" Grid.Row="3"/>
    </Grid>
    
    0 comments No comments

0 additional answers

Sort by: Most helpful