【问题标题】:Xamarin Forms Expander On Expanding event?Xamarin Forms Expander On Expanding 事件?
【发布时间】:2021-11-19 10:50:51
【问题描述】:

我在 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 控件在 ListView 或 CollectionView 中使用时会显示不受欢迎的行为。目前我们建议不要在这些控件之一中使用 Expander。”
  • “Expander 控件还定义了一个 Tapped 事件,当点击 Expander 标头时会触发该事件。”。 “ ExpandState 枚举定义了以下成员: Expanding 表示 Expander 正在扩展...”

标签: c# xamarin.forms


【解决方案1】:

您可以在 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方法。

【讨论】:

  • 问题解决了吗?
猜你喜欢
  • 1970-01-01
  • 2016-11-13
  • 2018-02-19
  • 2018-12-01
  • 2019-11-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多