Hello,
Welcome to our Microsoft Q&A platform!
The expander does not auto-resize when elements are hidden via IsVisible={Binding Foobar}
To resize the Expander
, try calling the ForceUpdateSize method to update the size of the expander. For example, the size of the font is changed, it's necessary to call the method update the size.
Check the code:
<Expander x:Name="expander">
<Expander.Header>
<Label Text="Testing for Expander"
FontAttributes="Bold"
FontSize="Medium" />
</Expander.Header>
<Grid Padding="10">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Image Source="https://upload.wikimedia.org/wikipedia/commons/thumb/8/87/Golden_lion_tamarin_portrait3.jpg/220px-Golden_lion_tamarin_portrait3.jpg"
Aspect="AspectFill"
HeightRequest="120"
WidthRequest="120" />
<Label
Text="The details of the expander's content,The details of the expander's content,The details of the expander's content,The details of the expander's content,The details of the expander's content,The details of the expander's content,The details of the expander's content"
FontAttributes="Italic">
<Label.GestureRecognizers>
<TapGestureRecognizer Tapped="TapGestureRecognizer_Tapped" />
</Label.GestureRecognizers>
</Label>
</Grid>
</Expander>
Tap gesture event:
private void TapGestureRecognizer_Tapped(object sender, EventArgs e)
{
var label = sender as Label;
if (label.FontSize == Device.GetNamedSize(NamedSize.Default, label))
{
label.FontSize = Device.GetNamedSize(NamedSize.Large, label);
}
else
{
label.FontSize = Device.GetNamedSize(NamedSize.Default, label);
}
expander.ForceUpdateSize();
}
Effect gif: https://us.v-cdn.net/5019960/uploads/editor/3b/85d2wpveijbb.gif
Check the link:
https://learn.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/expander#resize-an-expander-at-runtime
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.