[英]Xamarin Forms Expander On Expanding event?
我在 Xamarin.Forms 中使用扩展器
<xct:Expander PropertyChanging="Expander_PropertyChanging" PropertyChanged="Expander_PropertyChanged">
我想知道扩展器何时显示隐藏部分(扩展时)是否有事件
我可以看到 Expander 有这两个事件(PropertyChanging 和 PropertyChanged)
void Expander_PropertyChanging(System.Object sender, Xamarin.Forms.PropertyChangingEventArgs e)
{
}
void Expander_PropertyChanged(System.Object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
}
然而,这些每秒都会运行,即使我没有扩展,我正在寻找的东西在我扩展时会消失,调用一次方法。
您可以使用 Expander 中的Command方法。
每次用户点击展开或隐藏时都会触发该方法。
这是 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>
在 ContentPage 标记中添加xmlns:xct="http://xamarin.com/schemas/2020/toolkit"
。 下面是后台代码:
public ICommand myTest { set; get; }
public MainPage()
{
InitializeComponent();
myTest = new Command(() => Console.WriteLine("Command executed"));
BindingContext = this;
}
每次用户展开或隐藏时都会触发 myTest 方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.