How to place focus on my custom input , I am using mvvm , prism

Viewed 36

One query I have an entry in a contentview to be able to call it from another page. the question is how to locate the focus when I click on a button

<ContentView xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:xct="http://xamarin.com/schemas/2020/toolkit"
             x:Class="MovilERP.Controls.SacTextBox"
             x:Name="this">
    <Grid RowDefinitions="Auto,Auto">
        <!--#region Entry Normal-->
        <Grid RowDefinitions="Auto,1"
              ColumnDefinitions="*,Auto" RowSpacing="0">
              <Entry x:Name="txtBox"
                   Margin="{OnPlatform Android=0 , iOS=5}"
                   Text="{Binding Text, Source={x:Reference this}}"
                   PlaceholderColor="{DynamicResource PlaceHolderColorEntry}"
                   Style="{StaticResource EstiloEntry}"
                   IsPassword="{Binding ShowIcoPassword, Source={x:Reference this}}"
                   IsSpellCheckEnabled="{Binding IsCorrector, Source={x:Reference this}}"
                   IsTextPredictionEnabled="True">
</grid>
</grid>
</Conteview>
 
this is how i invoke it from another page               
<sofadControls:SacTextBox
                                x:Name="Descripcion"
                                Grid.Column="1"
                                Placeholder="Descripción"
                                SacAlineacion="Start"
                                SacValidacion="AlfaNumerico"
                                Text="{Binding Source={RelativeSource AncestorType={x:Type dialogos:FrmArticulosGeneralViewModel}}, Path=DetalleActual.Descripcion}"/>

In this way I try to invoke the focus but it does not work

Descripcion.Focus();
1 Answers

you need to create a public method in your control

public void Focus()
{
  txtBox.Focus();
}

then you can call that public Focus method from the oage that contains your control

Related