xamarin/Xamarin.Forms

Focused and UnFocused event of the Editor is not triggered when Editor’s renderer (EditText) is added as custom renderer in Xamarin Forms Android

开放

#4,231 创建于 2018年10月26日

 (1 条评论) (0 个反应) (0 位负责人)C# (1,926 个派生)batch import
e/4 :clock4:help wantedinactivep/Androidt/bug :bug:up-for-grabs

仓库指标

星标
 (5,644 个星标)
PR 合并指标
 (30 天内没有已合并 PR)

描述

Description

In my scenario I have added Editor’s renderer (EditText) as custom renderer for my custom layout, FousChanged event of EditText triggers properly but Focused and UnFocused event of Editor is not triggering. When I analyzed the issue, Focused and UnFocused event will be triggered when IsFocused property of Editor is True, in my scenario IsFocused property is not assigned to True. Since, it is read only property I cannot manually assign IsFocused as true. Could you please suggest any override method to check the IsFocused property and also, please provide details about when IsFocused will be assigned as True. Kindly find the code snippet and sample below,

Code snippet:

public class CustomEditor : Editor
 {
 }

CustomEditor customEditor = new CustomEditor();


protected override void OnElementChanged(ElementChangedEventArgs<CustomStack> e)

{

Android.Widget.ScrollView stack = new Android.Widget.ScrollView(Context);

if (e.NewElement != null)

{

var renderer = Platform.CreateRenderer(customEditor);

var nativeEditor = RendererHelper.GetNativeView(renderer.View);


(nativeEditor as EditText).FocusChange += Handle_FocusChange;

nativeEditor.RemoveFromParent();

stack.AddView(nativeEditor);


SetNativeControl(stack);

}
 base.OnElementChanged(e);
 }

Sample:
CustomEditor.zip

Note: This scenario works properly in Xamarin Forms UWP and iOS.

Regards, Ganeshamoorthy C

贡献者指南