zoukankan      html  css  js  c++  java
  • Xamarin.Forms之OnElementPropertyChanged那些事

    这是一篇不完善的笔记,并不是教程。

    今天遇到一些奇怪的问题,使用CustomRenderer为Picker添加TextColor属性,始终无法触发OnElementPropertyChanged,进过几轮测试后发现一些问题。

    1.在Control创建的过程中,自定义的属性是无法接受到消息的

    OnElementPropertyChanged中实际上是有触发的,但不是TextColorProperty,而是Renderer Width X Y Height 5个VisualElement的属性,即使是Picker的Title属性或者VisualElement的其他属性,譬如IsEnabled,均无法触发,Control创建时触发的仅且只有那5个属性

    但是在创建完成后,修改BinableProperty的任何属性均会触发

    这个好像是Forms的设定问题,下面有该问题的讨论

    http://forums.xamarin.com/discussion/26060/why-is-onelementpropertychanged-not-called-on-viewrenderer

    2.如果Property的属性设置的是同一值,则也不会触发OnElementPropertyChanged

    ViewRenderer<TView,TNativeView>中的:

    protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
    {
        if (e.get_PropertyName() == VisualElement.BackgroundColorProperty.PropertyName)
        {
            this.UpdateBackgroundColor();
            return;
        }
        if (e.get_PropertyName() == VisualElement.InputTransparentProperty.PropertyName)
        {
            TElement element = this.Element;
            this.InputTransparent = element.InputTransparent;
        }
        if (e.get_PropertyName() == VisualElement.IsEnabledProperty.PropertyName)
        {
            this.UpdateIsEnabled();
        }
    }

    大部分Control的Renderer都是继承上面的,但实际上该方法仅对三个Property进行了默认处理,未对值是否一致进行判断(可以通过去掉base.OnElementPropertyChanged (sender, e);进行测试),也就是问题2,是在这之前进行处理的,暂未发现在哪里

  • 相关阅读:
    娃娃机 解题报告
    ecshop
    多字节字符串 函数
    电商中设置满包邮,满减等促销搞活动;电商平台同步到第三方,日志记录
    PHP文件操作
    apache重写字段详细说明
    httpc服务器错误类型大全
    正则入门简易
    php100 编程小技巧
    memcache
  • 原文地址:https://www.cnblogs.com/yz1311/p/4728316.html
Copyright © 2011-2022 走看看