This is a migrated thread and some comments may be shown as answers.

Acceding Item in ContentView to set the focus.

2 Answers 150 Views
SlideView
This is a migrated thread and some comments may be shown as answers.
Pierre
Top achievements
Rank 2
Iron
Iron
Pierre asked on 30 Jan 2019, 07:41 PM

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 Answers, 1 is accepted

Sort by
0
Pierre
Top achievements
Rank 2
Iron
Iron
answered on 30 Jan 2019, 08:41 PM
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.
0
Didi
Telerik team
answered on 04 Feb 2019, 09:11 AM
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
Tags
SlideView
Asked by
Pierre
Top achievements
Rank 2
Iron
Iron
Answers by
Pierre
Top achievements
Rank 2
Iron
Iron
Didi
Telerik team
Share this question
or