Acceding Item in ContentView to set the focus.

3 posts, 0 answers
  1. Pierre
    Pierre avatar
    260 posts
    Member since:
    Apr 2007

    Posted 30 Jan 2019 Link to this post

    HI, I follow this

    for the BindingContext, but now I need to set the focus to a RadEntry inside a content view. The ViewModel call the function with the MessagingCenter, but I do not know how to access the RadEntry in the code behind.


    <telerikPrimitives:RadSlideView x:Name="SlideView" SelectedIndex="{Binding SlideViewIndex}">
            <commands:CustomSlideViewCommand Id="SlidingToIndex" Command="{Binding BindingContext.SlidindToIndexCommand}"/>
            <commands:CustomSlideViewCommand Id="SlidedToIndex" Command="{Binding BindingContext.SlidedToIndexCommand}" />
            <x:Array Type="{x:Type ContentView}">
                <ContentView x:Name="Etape1CV">
                    <StackLayout Margin="10" x:Name="Etape1SL">
                        <Label>Scanner ou entrer un code de localisation</Label>
                        <Entry x:Name="TestEntry">ALLO</Entry>
                        <telerikInput:RadEntry x:Name="CodeLoca" WatermarkText="Code" IsTabStop="True" />
                    <Label HorizontalOptions="Center"
                           Text="Other View"
                           TextColor="Blue" />
                    <Label HorizontalOptions="Center"
                           Text="Another View"
                           TextColor="Red" />



    public DecompteLocalisationView ()
        InitializeComponent ();
        BindingContextHelper.CurrentPageBindingContext = this.BindingContext;
        MessagingCenter.Subscribe<string>(this, "SetFocusToCodeLoca", (sender) => {
            foreach(ContentView View in SlideView.ItemsSource)
                //THEN SET THE FOCUS
                //RadEntry Tb = CodeLoca as RadEntry;
                //if (Tb.Text.Length > 0)
                //    Tb.CursorPosition = 0;
                //    Tb.SelectionLength = Tb.Text.Length;



  2. Pierre
    Pierre avatar
    260 posts
    Member since:
    Apr 2007

    Posted 30 Jan 2019 in reply to Pierre Link to this post

    In the same idea, I follow your explanation for the bindingContext. That work only the second time I enter the view. The first time no error, but no binding.
  3. Didi
    Didi avatar
    333 posts

    Posted 04 Feb 2019 Link to this post

    Hi Pierre,

    Thank you for the provided code.

    The described scenario could be achieved through a Custom Entry control that inherits from RadEntry control. I have created a sample project that shows how this could be achieved.

    Please take a look at the attached file and let me know if you have any additional question.

    Progress Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top