c# - How to prevent Xamarin.Forms.Entry Keyboard to be Unfocused when Pressing a Button -


i making chat functionality, , how xaml snippet looks like:

<stacklayout grid.row="1" orientation="horizontal" heightrequest="50">     <entry x:name="chatfield" text="{binding currentmessagetext}" placeholder="{binding messagetextplaceholder}" horizontaloptions="fillandexpand"/>     <button text="send" backgroundcolor="transparent" command="{binding sendmessagecommand}"/> </stacklayout> 

i have entry control , button control binded command sends text in chatfield.

and want mimic chat apps standard wherein pressing send button not unfocus or hides keyboard.

enter image description here

unfortunately, right when press send button - automatically unfocus keyboard entry cell.

initial steps made prevent this, on viewmodel sendmessagecommand have:

var chatentry = currentpage.findbyname<entry>("chatfield"); chatentry.focus(); 

but makes weird behaviour of pushing list view up.

enter image description here

had solved using custom renderer on ios:

    public class chatentryviewrenderer : entryrenderer     {         protected override void onelementpropertychanged(object sender, system.componentmodel.propertychangedeventargs e)         {             if (e.propertyname == visualelement.isfocusedproperty.propertyname)             {                 if (control != null)                 {                     var chatentryview = this.element chatentryview;                     control.shouldendediting = (uitextfield textfield) =>                     {                         return !chatentryview.keepopen; // keepopen custom property added , set on viewmodel if want entry keyboard kept open set true.                     };                 }             }              base.onelementpropertychanged(sender, e);         }     } 

what uses control's shouldendediting event triggers when edittext loses focus or if keyboard unfocused.


Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -