Detect slide event

7 posts, 0 answers
  1. Kevin
    Kevin avatar
    7 posts
    Member since:
    Mar 2017

    Posted 15 Apr 2018 Link to this post

    I want to be able to detect when the page changes so that I can call a particular method when a certain page is shown.

    The documentation describes how to do this in the code-behind but I am using a mvvm framework and I cannot get this part to work from my view model.

    Does anyone know how I can detect the slide event from my view model? 

  2. Lance | Technical Support Engineer, Principal
    Admin
    Lance | Technical Support Engineer, Principal avatar
    1002 posts

    Posted 16 Apr 2018 Link to this post

    Hi Kevin,

    You can TwoWay bind to SelectedIndex and perform your additional logic in the bound property's setter or you can use an EventToCommandBehavior with the SelectionChanged event.

    Regards,
    Lance | Tech Support Engineer, Sr.
    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
  3. Kevin
    Kevin avatar
    7 posts
    Member since:
    Mar 2017

    Posted 25 Apr 2018 in reply to Lance | Technical Support Engineer, Principal Link to this post

    Hi Lance,

    Thanks for your response.

    I had solved my issue of detecting the slide event by creating a custom class as mentioned in the documentation.  This probably wasn't the best of methods to use but it did work and was simple to implement.

    I've now come across a different issue which doesn't seem to work using the custom class method that I have used so I have now started to look into what you have suggested regarding binding the SelectedIndex, but something about this doesn't seem to be working correctly so I was wondering whether you could assist.

    The problem seems to occur when I set the binding property to TwoWay - when it's set to OneWay, it all works fine (although I can't detect the swipe event); but when it's set to TwoWay, for some reason I have to swipe twice to get the page to change.

    I've put some breakpoints on the bindable property and it seems to only get called every other swipe so although it does detect the swipe event allowing me to call other methods when certain pages are shown, having to swipe twice to change page once isn't ideal.

    In Summary: OneWay binding works correctly but TwoWay binding requires the page to be swiped twice.

     

    Do you have any ideas why it is working like this and how I can solve my problem?

    Thanks...

  4. Lance | Technical Support Engineer, Principal
    Admin
    Lance | Technical Support Engineer, Principal avatar
    1002 posts

    Posted 25 Apr 2018 Link to this post

    Hi Kevin,

    I'm not seeing that behavior. Here's an animated GIF of my attached demo:




    Give the demo a run and try it. For your convenience, here's the code:

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition/>
        </Grid.RowDefinitions>
             
        <Label Text="{Binding IndexDisplay}" HorizontalTextAlignment="Center"/>
             
        <telerikPrimitives:RadSlideView SelectedIndex="{Binding Index, Mode=TwoWay}"
                                        Grid.Row="1">
            <telerikPrimitives:RadSlideView.ItemsSource>
                <x:Array Type="{x:Type x:String}">                   
                    <x:String>View 1</x:String>
                    <x:String>View 2</x:String>
                    <x:String>View 3</x:String>
                </x:Array>
            </telerikPrimitives:RadSlideView.ItemsSource>
        </telerikPrimitives:RadSlideView>
    </Grid>

    public class ViewModel : INotifyPropertyChanged
    {
        private int index;
        private string indexDisplay;
     
        public int Index
        {
            get => index;
            set
            {
                if (value == index)
                    return;
     
                index = value;
                OnPropertyChanged();
     
                IndexDisplay = $"The Selected Index is {value}";
            }
        }
     
        public string IndexDisplay
        {
            get => indexDisplay;
            set
            {
                if (value == indexDisplay)
                    return;
     
                indexDisplay = value;
                OnPropertyChanged();
            }
        }
     
     
        public event PropertyChangedEventHandler PropertyChanged;
        protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }
    }

    Check to see if there are other factors intercepting or resetting the value of your bound properties. Use Debug.WriteLine to output all the values at runtime and compare what you expect to the actual value.

    Regards,
    Lance | Tech Support Engineer, Sr.
    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
  5. Kevin
    Kevin avatar
    7 posts
    Member since:
    Mar 2017

    Posted 26 Apr 2018 in reply to Lance | Technical Support Engineer, Principal Link to this post

    Hi Lance,

    Thanks for the reply and attaching the demo, I'll give that a try as soon as I can.

    I've done some further testing around this issue and I've discovered something else that seems to tie into the animated GIF that you have attached.  When using the "< >" buttons the bound property is called every time, but when actually swiping the view the bound property is only called every other time.

    As it works correctly using the buttons this seems like a small bug, but just for clarification, at the moment I am using the free trial version of the Telerik controls.  My company has recently purchased the full version but we haven't had chance to update our code yet so I don't know if this could be part of my issue.

    Thanks for your assistance so far...

  6. Lance | Technical Support Engineer, Principal
    Admin
    Lance | Technical Support Engineer, Principal avatar
    1002 posts

    Posted 26 Apr 2018 Link to this post

    Hi Kevin,

    Thank you for the information regarding the licensing scenario, it led me to wonder if you're possibly using an older version of UI for Xamarin because you're trial has run out and there have been new releases since you would have started the trial. In those releases we've included several fixes for the SlideView, especially one fix a couple versions ago in a scenario when SelectedIndex is bound and the InfiniteScrolling is enabled.

    Manage Licensed Users

    Have your company add you as a Licensed User on the license. This not only allows you to create support tickets, but you'll be able to get the latest bits 

    This is really easy and only takes 20-30 seconds to do:

    1 - Go to the Manage Licensed Users portal
    2 - Remove the current user from the license (don't worry the owner continues to own the license and can change Licensed User at any time)
    3 - Assign you as the Licensed User


    Once you're the Licensed User, download and update your UI for Xamarin installation, then update your project's Telerik references.

    In the meantime, I'll continue to see if I can replicate the issue using the latest version and slide-only operation. It may already be fixed, but I'll double check to make sure.

    Regards,
    Lance | Tech Support Engineer, Sr.
    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
  7. Kevin
    Kevin avatar
    7 posts
    Member since:
    Mar 2017

    Posted 27 Apr 2018 in reply to Lance | Technical Support Engineer, Principal Link to this post

    Hi Lance,

    I've now updated to the FULL version of the controls and retested and everything is working fine now.

    I want to thank you for your assistance with this issue...

Back to Top