简体   繁体   English

Xamarin Forms 扩展器 在扩展事件中?

[英]Xamarin Forms Expander On Expanding event?

I am using an Expander in Xamarin.Forms我在 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)我可以看到 Expander 有这两个事件(PropertyChanging 和 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.您可以使用 Expander 中的Command方法。

This method will be triggered every time the user clicks to expand or hide.每次用户点击展开或隐藏时都会触发该方法。

Here is the xaml code:这是 xaml 代码:

<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.在 ContentPage 标记中添加xmlns:xct="http://xamarin.com/schemas/2020/toolkit" 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.每次用户展开或隐藏时都会触发 myTest 方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM