1 回答

TA貢獻1789條經驗 獲得超10個贊
在此處查看有關自定義渲染器的文章:實現視圖 它包含自定義渲染器的 OnElementChanged 方法的模板:
protected override void OnElementChanged (ElementChangedEventArgs<NativeListView> e)
{
base.OnElementChanged (e);
if (Control == null) {
// Instantiate the native control and assign it to the Control property with
// the SetNativeControl method
}
if (e.OldElement != null) {
// Unsubscribe from event handlers and cleanup any resources
}
if (e.NewElement != null) {
// Configure the control and subscribe to event handlers
}
}
因此,您應該在 OldElement 不為 null 時取消掛鉤事件,并在出現 NewElement 時掛鉤它們。
至于評論中的后續問題(如果上面的第二個沒有被觸發,我們是否應該取消訂閱):我的理解是這兩個對象的生命周期(所以渲染器和本機控件)是相同的,在這種情況下沒有需要手動取消訂閱事件。如果我錯了,請糾正我。
- 1 回答
- 0 關注
- 157 瀏覽
添加回答
舉報