首页 > 解决方案 > 自定义渲染器中的 e.OldElement 和 e.NewElement

问题描述

这里微软告诉我们在自定义渲染器中使用e.OldElement和:e.NewElement

...为防止内存泄漏,在实例化新的本机控件时必须小心...

...

  if (e.OldElement != null) {
    // Unsubscribe from event handlers and cleanup any resources
  }

  if (e.NewElement != null) {
    // Configure the control and subscribe to event handlers
  }

另一方面,他们在这里忽略了自己的建议:

    if (Control != null) {
        // do whatever you want to the UITextField here!
        Control.BackgroundColor = UIColor.FromRGB (204, 153, 255);
        Control.BorderStyle = UITextBorderStyle.Line;
    }

那么我们是否需要担心它们?还是取决于情况(因此:哪个在哪里?)?

标签: xamarinxamarin.formsxamarin.iosxamarin.android

解决方案


推荐阅读