Improving a control–Windows Phone 7 Wheel Control

imageThe wheel control, thanks to Rene Schulte for telling me what the term on the street was, is used in a few places in Windows Phone 7 (WP7) and Nick Randolph created a user control to mimic it.  It was great but needed a few little tweaks.  Nick did all the heavy lifting on this.

Currently you can go to his blog entry on it here:  Windows Phone7 Wheel Control – Updated to get the most up to date version.

What I did:

  • Enabled flick gestures
  • Removed a flicker on press
  • On lost focus, snap to grid
  • Allowed for SelectedIndex to be set via XAML

What Nick was doing was levering the ManipulationCompleted event on the scroller in the ListBox and then snapping to grid.  The problem is that when you flick, that event is fired the second your finger is removed from the screen.  The item should snap when it is done moving.  Peter Torr has a blog post on detecting if a list is scrolling or not so I leveraged that bit of code.

I then changed how the CurrentStateChanging event worked in Peter’s code to work with the wheel code.

group.CurrentStateChanging += (s, args) =>
	{
			InvokeCurrentStateChanging(args);
			_currentState = args.NewState;
			if (_currentState.Name == "NotScrolling" && !_userClickedOnItem)
				SnapToGrid();
	};

Now to get this to work properly, there are lots of use cases you have to watch out for.

  • Flicking and click
  • Flicking and lost focus
  • Flicking and it stops scrolling
  • Clicking but not flicking

Fixing the flickering issue fixed and caused a few of the issues.

The root cause of the flickering was how Nick was handling the LostFocus when you would select an item by clicking.  Flicking does not cause this behavior until it runs out of items / stops moving.  LostFocus is fired before SelectionChanged and he would hide everything then show update it.

The MouseEnter event however happens before LostFocus (the magic of breakpoints :-)) so with a simple Boolean to verify that they are clicking and on UpdateFocus, only update if a click event is not in progress.   On MouseLeave and on Scroller_ManipulationCompleted, that boolean, _userClickedOnItem, is set to false.

As is, this control is not currently a Date or Time picker control.  With a bit of work however, it can easily become that.

tseu Jan 9, 2011 @ 4:11 PM

# re: Improving a control–Windows Phone 7 Wheel Control
thank you but a code sample would have been clearlier because Nick didn't implement this into this code.

dan Nov 3, 2014 @ 2:58 AM

# re: Improving a control–Windows Phone 7 Wheel Control
I didn't like windows phones at first, but they started growing on me. I think they will keep improving with time, but it will be hard for them to catch up to Android.

Lina Nov 3, 2014 @ 4:41 AM

# re: Improving a control–Windows Phone 7 Wheel Control
I can't make a statement about Windows phone taking into account that I'm using Android. On the other hand I agree that is very difficult to catch up the latest Android improvements. But in time, maybe the situation will change.

Edy Nov 4, 2014 @ 4:59 AM

# re: Improving a control–Windows Phone 7 Wheel Control
Thank you very much for sharing this information with us. I'm actually using WP7 and it works pretty good for me! Although I will read Nick's blog.

Samuel Nov 23, 2014 @ 4:03 AM

# re: Improving a control–Windows Phone 7 Wheel Control
I don't use very often windows phone devices, these are not that bad. They just got a too simple operating system, you get boored faster.

didi Jan 23, 2015 @ 6:44 AM

# re: Improving a control–Windows Phone 7 Wheel Control
If you get it to be precise and work well I think it's going to be great. I like the idea and I think it's worth working at.

dan Feb 6, 2015 @ 3:51 AM

# re: Improving a control–Windows Phone 7 Wheel Control
I like things to be simple and easy to use. Sure, some of these things can help you sometimes, but I think you only use some of these features once every...I don't know...few weeks, and in the meantime they're just in your way.

bianca Mar 18, 2015 @ 8:57 AM

# re: Improving a control–Windows Phone 7 Wheel Control
Windows phones will never catch on. I really don't see a future for them. Android and iOS are the only true players on this market.

Miruna Mar 19, 2015 @ 5:27 AM

# re: Improving a control–Windows Phone 7 Wheel Control
I've always thought that it takes a lot of determination to achieve something higher in programming. First, I think that there are a lot of competitiveness at this level, and then at how difficult it seems to me this job.

elena Mar 31, 2015 @ 7:49 AM

# re: Improving a control–Windows Phone 7 Wheel Control
I have a wp7 mobile and i like it now but with this great idea i will love it

Jasmine Apr 9, 2015 @ 8:29 AM

# re: Improving a control–Windows Phone 7 Wheel Control
I like the way you work, it seems that you focus only on the important details related to the field of programming. I expect you to accomplish something absolutely fabulous in this technological area, so I'll still watching your activity.

Valeriu Apr 24, 2015 @ 7:57 AM

# re: Improving a control–Windows Phone 7 Wheel Control
I am really impressed by yout technical initiatives, because you are actually trying to bring to life your passion for the it field. This is a great attitude and I believe that our level of development will increase if each of us will do something relevant in the domain that we are currently working.

Vasile May 29, 2015 @ 4:17 AM

# re: Improving a control–Windows Phone 7 Wheel Control
Nice work dude. I like when people like you, who have the knowledge, are trying to make something useful, not only for them.

Post a Comment

Please add 2 and 2 and type the answer here: