[英]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.