【问题标题】:How to check if all properites of element are loaded?如何检查元素的所有属性是否已加载?
【发布时间】:2016-06-29 15:18:04
【问题描述】:

我正在创建一些自定义视图元素:

public class ExtendableButtonList : StackLayout
{
    public static readonly BindableProperty NewSlotNameProperty = BindableProperty.Create(
      propertyName: "NewSlotName",
      returnType: typeof(string),
      declaringType: typeof(ExtendableButtonList),
      defaultValue: default(string));

    public string NewSlotName
    {
        get { return (string)GetValue(NewSlotNameProperty); }
        set { SetValue(NewSlotNameProperty, value); }
    }

    public delegate void OnLoadHandler(ExtendableButtonList ebl);
    public event OnLoadHandler OnLoadEvent;

    public ExtendableButtonList (){
       //not all properies are loaded at this point
    }
    [...]
}

我需要对通过 XAML 传递给该对象的属性执行一些操作。不幸的是,在调用 ExtendableButtonList 类的构造函数时,并不是所有的 BindableProperties 都被加载。它们稍后会出现。

我如何知道该对象中的所有属性何时加载?何时调用 OnLoadEvent 让我的应用知道该对象已准备好进一步使用?

【问题讨论】:

  • 您是否尝试覆盖 OnBindingContextChanged?猜猜这是一个检查的好地方。
  • @jzeferino 是正确的。我在这里回答了一个类似/重复的问题:stackoverflow.com/questions/37867863/…
  • 我在帖子中添加了我的答案。因为这不是那个问题的重复。谢谢。

标签: xamarin xamarin.forms


【解决方案1】:

在这种特殊情况下,您应该覆盖 OnBindingContextChanged 来进行验证。

你可以看到hereOnBindingContextChanged的一个很好的解释

【讨论】:

    猜你喜欢
    • 2017-12-30
    • 1970-01-01
    • 1970-01-01
    • 2020-07-09
    • 2019-04-30
    • 2016-10-05
    • 1970-01-01
    • 2013-05-16
    • 2014-12-16
    相关资源
    最近更新 更多