我正在使用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)
{
}然而,它们每秒都在运行,即使在我没有扩展的时候,我正在寻找的是,当我扩展时,调用一次方法。
发布于 2021-11-19 02:50:52
可以在扩展器中使用命令方法。
每次用户单击以展开或隐藏时,都会触发此方法。
下面是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方法。
https://stackoverflow.com/questions/70021476
复制相似问题