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

Add logic to ManipulationStarted event

1 Answer 64 Views
ListPicker
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Oleg
Top achievements
Rank 1
Oleg asked on 23 Nov 2012, 10:43 AM
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

1 Answer, 1 is accepted

Sort by
0
Accepted
Kiril Stanoev
Telerik team
answered on 26 Nov 2012, 11:34 AM
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.
Tags
ListPicker
Asked by
Oleg
Top achievements
Rank 1
Answers by
Kiril Stanoev
Telerik team
Share this question
or