I'm creating a form in Xaml using Xamrin which contains absolute layout in which i'm hiding a stacklayout. but one more stacklayout just down below of hidden stacklayout but hidden stacklayout is taking up space.
What i want to do.When i did hide one stacklayout another stacklayout should take place of hidden staklayout.
Thanks for help and supports.
I've resolved the issue:
I followed this link https://forums.xamarin.com/discussion/83632/hiding-and-showing-stacklayout in this link they said that use grid and make row height auto and it will automatically adjust the extra space of layout.
<Grid VerticalOptions="Fill">
<Grid.RowDefinitions>
<RowDefinition Height="100"/>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<StackLayout Grid.Row="1" Spacing="20">
<StackLayout Margin="10,0">
<Label Text="lable 1" VerticalOptions="Center" FontSize="Small" />
<Label Text="lable 2" VerticalOptions="Center" FontSize="Small" />
</StackLayout>
<StackLayout IsVisible="{Binding IsStudent}" Margin="10,0">
<Label Text="lable3" VerticalOptions="Center" FontSize="Small" />
<Label Text="lable 4" VerticalOptions="Center" FontSize="Small" />
<Label Text="lable 5" VerticalOptions="Center" FontSize="Small" />
<Label Text="lable 6" VerticalOptions="Center" FontSize="Small" />
</StackLayout>
</StackLayout>
<StackLayout Grid.Row="2" Spacing="20" >
<local:Button
x:Name="btnSave"
Text="Submit"
VerticalOptions="End"
HorizontalOptions="FillAndExpand"
IsVisible="{Binding IsBusy, Converter={x:Static local:InverseBoolConverter.Instance}}"
AutomationId="saveButton" />
</StackLayout>
</Grid>
No need for a grid. Set the IsVisible AND HeightRequest properties.
MyStackLayout.IsVisible = false;
MyStackLayout.HeightRequest = 0; // trigger recalc of space layout.
The change in heightrequest triggers the desired recalculations.
I've too looked into why those hidden controls are taking space and well... they ARE taking space and that's it. You can do a simple addition and removing of labels. Something like this:
public class MyStack : StackLayout
{
Label
_label1 = new Label(),
_label2 = new Label(),
_label3 = new Label();
public void ShowLabels()
{
Children.Add(_label1);
Children.Add(_label2);
Children.Add(_label3);
}
public void HideLabels()
{
Children.Remove(_label1);
Children.Remove(_label2);
Children.Remove(_label3);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With