'Xamarin Forms Expander On Expanding event?
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.
Solution 1:[1]
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.
Solution 2:[2]
From the documentation https://docs.microsoft.com/en-us/xamarin/community-toolkit/views/expander
The ExpandState enumeration defines the following members:
- Expanding indicates that the Expander is expanding.
- Expanded indicates that the Expander is expanded.
- Collapsing indicates that the Expander is collapsing.
- Collapsed indicates that the Expander is collapsed.
The Expander control also defines a Tapped event that's fired when the Expander header is tapped.
In addition, Expander includes a ForceUpdateSize method that can be called to programmatically resize the Expander at runtime.
Solution 3:[3]
By that assignment you make your list instance inconsistent. An empty list would have both its head and tail member set to null and its size equal to 0.
That's why you should not just alter a member of your class like that. You should probably even make them private to prevent the caller from doing such manipulations. If you want to have a way to empty a list, then create a proper method for it, which takes care of keeping the properties consistent:
public void clear() {
head = tail = null;
size = 0;
}
And in your main code, just call that sLL.clear() method.
If you keep a reference to a node, you will always be able to access it. To really lose a node, you must get rid of all references to it.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Wen xu Li - MSFT |
| Solution 2 | dhin |
| Solution 3 | trincot |
