Dotneteers.net
All for .net, .net for all!

SurfCube on Mango Part 4 – fighting with the ListPicker control

On SurfCube, we are using the ListPicker control from the Silverlight for Windows Phone Toolkit. The latest (August 2011) version of this Toolkit has a bug – it doesn’t work in ScrollViewers. It simply does not open. First we thought the problem was with Pivots / Panoramas – then, stripping away the controls one by one, we found that it was actually the ScrollViewer that stole the tap event somehow.

After that, it was easy to find an existing solution at http://forums.create.msdn.com/forums/p/90708/543239.aspx#543239. What we did is package the code there into a nice small behavior (sorry for the weird formatting, just want to make sure it fits the screen):

using System.Windows.Interactivity;
using Microsoft.Phone.Controls;
 
namespace My3DBrowser.Behaviors
{
    public class ListpickerInScrollViewerFixBehavior : 
                 Behavior<ListPicker>
    {
        protected override void OnAttached()
        {
            base.OnAttached();
            AssociatedObject.Tap += ListPickerTap;
        }
 
        bool isOpen;

private void ListPickerTap(
object sender, System.Windows.Input.GestureEventArgs e)

        {
            if (!isOpen)
            {
                AssociatedObject.Open();
                isOpen = true;
            }
            else
            {
                isOpen = false;
            }
        }
    }
}

 

And that’s it… just apply this behavior to any ListPicker that doesn’t behave correctly in a ScrollViewer.

Note: This is not a perfect solution. For example, after the ListPicker opens, the containing scrollviewer should scroll so that it is entirely visible. We “solved” this problem by putting the listpickers on top – if anybody has a better solution, I am all ears (eyes?)


Posted Sep 11 2011, 08:16 PM by vbandi

Comments

Dew Drop – September 12, 2011 | Alvin Ashcraft's Morning Dew wrote Dew Drop &ndash; September 12, 2011 | Alvin Ashcraft&#039;s Morning Dew
on Mon, Sep 12 2011 14:13

Pingback from  Dew Drop – September 12, 2011 | Alvin Ashcraft's Morning Dew

SurfCube on Mango Part 4 ??? fighting with the ListPicker control wrote SurfCube on Mango Part 4 ??? fighting with the ListPicker control
on Mon, Sep 12 2011 14:30

Pingback from  SurfCube on Mango Part 4 ??? fighting with the ListPicker control