Acceding Item in ContentView to set the focus.

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

    Posted 30 Jan Link to this post

    HI, I follow this

    https://docs.telerik.com/devtools/xamarin/knowledge-base/slideview-access-parent-bindingcontext

    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.

    View:

    <telerikPrimitives:RadSlideView x:Name="SlideView" SelectedIndex="{Binding SlideViewIndex}">
        <telerikPrimitives:RadSlideView.Commands>
            <commands:CustomSlideViewCommand Id="SlidingToIndex" Command="{Binding BindingContext.SlidindToIndexCommand}"/>
            <commands:CustomSlideViewCommand Id="SlidedToIndex" Command="{Binding BindingContext.SlidedToIndexCommand}" />
        </telerikPrimitives:RadSlideView.Commands>
        <telerikPrimitives:RadSlideView.ItemsSource>
            <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" />
                    </StackLayout>
                </ContentView>
                <ContentView>
                    <Label HorizontalOptions="Center"
                           VerticalOptions="CenterAndExpand"
                           Text="Other View"
                           TextColor="Blue" />
                </ContentView>
                <ContentView>
                    <Label HorizontalOptions="Center"
                           VerticalOptions="CenterAndExpand"
                           Text="Another View"
                           TextColor="Red" />
                </ContentView>
            </x:Array>
        </telerikPrimitives:RadSlideView.ItemsSource>
    </telerikPrimitives:RadSlideView>

     

    CodeBehind

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

     

    Thanks

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

    Posted 30 Jan 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
    Admin
    Didi avatar
    186 posts

    Posted 04 Feb 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.

    Regards,
    Didi
    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