Wednesday, March 19, 2014

Weeeee fun with the ListPicker control Windows Phone

I was trying to get this control to behave.  I was using the SelectionChanged event thinking it
would behave like the trusty combo box.  This is not the case.  The ListPicker is "always on"
so it will fire when the page loads or say other events like... setting the visibility to true.
This is what bit me.  Fortunately, the solution to this is quite simple.



Solution:

    private void SomeListPicker_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        // Make sure we don't handle the event during initiation.
        if (e.RemovedItems != null && e.RemovedItems.Count > 0)
        {
            if (this.SomeListPicker.SelectedItem != null)
            {
               // Do actual stuff.                   
            }
         }           
    }

Source:
http://samidipbasu.com/2011/05/19/fun-with-toolkit-listpicker-selections/

No comments:

Post a Comment