I am using an Expander in Xamarin.Forms
<xct:Expander PropertyChanging="Expander_PropertyChanging" PropertyChanged="Expander_PropertyChanged">
I am wondering if there is an event for when the expander is showing the hidden section (on expanding)
I can see that Expander has these 2 events (PropertyChanging and PropertyChanged)
void Expander_PropertyChanging(System.Object sender, Xamarin.Forms.PropertyChangingEventArgs e)
{
}
void Expander_PropertyChanged(System.Object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
}
However these run every second, even when I am not expanding, What I am looking for is away for when I am expanding, call a method once.
You can use the Command method in Expander.
This method will be triggered every time the user clicks to expand or hide.
Here is the xaml code:
<StackLayout>
<xct:Expander Command="{Binding myTest}">
<!-- Use the Command method above -->
<xct:Expander.Header>
<Label Text="Baboon"
FontAttributes="Bold"
FontSize="Medium" />
</xct:Expander.Header>
<Grid Padding="10">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Image Source="http://upload.wikimedia.org/wikipedia/commons/thumb/f/fc/Papio_anubis_%28Serengeti%2C_2009%29.jpg/200px-Papio_anubis_%28Serengeti%2C_2009%29.jpg"
Aspect="AspectFill"
HeightRequest="120"
WidthRequest="120" />
<Label Grid.Column="1"
Text="Baboons are African and Arabian Old World monkeys belonging to the genus Papio, part of the subfamily Cercopithecinae."
FontAttributes="Italic" />
</Grid>
</xct:Expander>
</StackLayout>
Add xmlns:xct="http://xamarin.com/schemas/2020/toolkit"
in the ContentPage tag. Here is the background code:
public ICommand myTest { set; get; }
public MainPage()
{
InitializeComponent();
myTest = new Command(() => Console.WriteLine("Command executed"));
BindingContext = this;
}
The myTest method will be triggered every time the user expands or hides.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.