Add logic to ManipulationStarted event

2 posts, 1 answers
  1. Oleg
    Oleg avatar
    10 posts
    Member since:
    Aug 2012

    Posted 23 Nov 2012 Link to this post

    I want to show advertise page to unregistered users which want to change value of listpicker.

    <ti:RadListPicker x:Name="Filter"
                                 Margin="0,-12,0,0"
                                 Height="Auto"
                                 ItemsSource="{Binding FilterOptions}"
                                 SelectedIndex="{Binding SelectedIndex}"                         
                                 PopupItemTemplate="{StaticResource PopupFilterTemplate}"
                                 PopupHeader="Select date"
                                 ItemTemplate="{StaticResource InlineFilterTemplate}">
     
                       <i:Interaction.Triggers>
                           <i:EventTrigger EventName="ManipulationStarted">
                               <mvvm:EventToCommand Command="{Binding TryShowFilterCommand}" PassEventArgsToCommand="True" />
                           </i:EventTrigger>
                       </i:Interaction.Triggers>
     
                   </ti:RadListPicker>


    In ViewModel:
    TryShowFilterCommand = new RelayCommand<ManipulationStartedEventArgs>((e) => {
         
        bool isPremium = false;
        if (e != null)
        {
            if (!isPremium) {
                navigation.NavigateTo(ViewModelLocator.BuyFullVersionPage);
                e.Handled = true;
                e.Complete();
            }
        }
    });
    It works for me.. from second time!
    In first time, i see my new page, then i see listpicker in fullscreen mode.
    But from the second time it works good.

    What is the reason? 
    Thank you
  2. Answer
    Kiril Stanoev
    Admin
    Kiril Stanoev avatar
    1512 posts

    Posted 26 Nov 2012 Link to this post

    Hello Oleg,

    Thank you for contacting us. Indeed there appears to be some inconsistency when handling the ManipulationStartedEvent. As a workaround, I'd suggest you do the following:

    public partial class MainPage : PhoneApplicationPage
    {
        public RelayCommand<ManipulationStartedEventArgs> TryShowFilterCommand { get; set; }
        private bool isPremium = false;
     
        // Constructor
        public MainPage()
        {
            this.InitializeComponent();
     
            // subscribe to the StateChanged event so that we can close the popup in the handler
            this.Filter.StateChanged += new EventHandler<Telerik.Windows.Controls.ListPickerStateChangedEventArgs>(Filter_StateChanged);
            // set some itemssource
            this.Filter.ItemsSource = Enumerable.Range(0, 10);
     
            // initialize command
            this.TryShowFilterCommand = new RelayCommand<ManipulationStartedEventArgs>((e) =>
            {
                if (e != null)
                {
                    if (!this.isPremium)
                    {
                        e.Handled = true;
                        e.Complete();
                        NavigationService.Navigate(new Uri("/PurchasePage.xaml", UriKind.RelativeOrAbsolute));
                    }
                }
            });
     
            this.DataContext = this;
        }
     
        private void Filter_StateChanged(object sender, Telerik.Windows.Controls.ListPickerStateChangedEventArgs e)
        {
            if (!this.isPremium)
            {
                if (this.Filter.State == Telerik.Windows.Controls.ListPickerState.Expanding || this.Filter.State == Telerik.Windows.Controls.ListPickerState.Expanded)
                {
                    this.Filter.IsExpanded = false;
                }
            }
        }
    }

    With the workaround above, if the isPremium flag is false then the ListPicker should not be opened. Also, to make this approach work, you'll have to configure the ListPicker to be in inline mode (ex: set the InlineModeThreshold property to a number greater than the number of items in the ListPicker collection). Once isPremium is true (I assume through a purchase), you can reset the InlineModeThreshold.

    Give it a try and let me know if this workaround is acceptable. Meanwhile, we'll do our best to support this scenario without the need of a workaround.
    All the best,
    Kiril Stanoev
    the Telerik team
    Have a suggestion or face a problem - you can use the Ideas & Feedback portal to submit ideas, feedback and vote for them.
  3. DevCraft banner
Back to Top