How to Disable Pivot / Panorama swipe gesture: Sliding inside Pivot Item
published on: 3/25/2011 | Views: N/A | Tags: Pivot Panorama Gestures
by WindowsPhoneGeek
Recently we received lots of questions about how to disable Pivot/Panorama gestures in WP7. So in this post I am going to give some suggestions.
Questions:
- How to disable/stop the flick gesture which is used to swipe/move between the various Pivots ?
- I have Pivot and a Slider inside it. So how to stop the movement of pivot screen while sliding?
The problem: Lets say that we have a Pivot and a Slider control in one of its items. So we want to be able to use the Slider without swiping the pages(stop the movement of pivot screen while sliding).
NOTE: Have in mind that allowing complex user input within a Panorama or a Pivot is not a recommended UX practice on Windows Phone.
Answer: However if you still want to disable Panorama/Pivot gestures then all you need to do in is just to set the IsHitTestVisible = false on the root pivot control.
- If set to TRUE: this means that the contained area of this UIElement can be used for hit-testing;
- If set to FALCE: a UIElement will not report any input/touch events, such as MouseLeftButtonDown, ManipulationStarted, ManipulationDelta, etc, and cannot receive focus. A routed input event that was originated by a different object can still route to or through an object in the object tree where IsHitTestVisible is false. The object where IsHitTestVisible is false can choose to handle that event, or can leave it unhandled so that it routes further up the object tree.
There are lots of different approaches of how to handle the IsHitTestVisible behavior. Here are all articles related to the problem that I managed to find on the web witch offer 5 different solutions of the problem:
- WP7 Tip: disabling the Pivot Control swipe gesture
- Making a Slider work nice with the Pivot [or Panorama] controls in Windows Phone 7
- Preventing the Pivot or Panorama controls from scrolling
- WP7 the Pivot and Bing Map dilemma
The easiest solution is to use Touch.FrameReported as James Ashley suggested.
Lets create a Pivot and place a Slider in one of its items. We will add an additional Border with Gray Background so that you will be able to see the exact position of the Slider element on the screen.


Here are how the code should looks like:
<controls:PivotItem Header="first">
<!--Double line list with text wrapping-->
<StackPanel>
<TextBlock Text="This is Pivot Control" FontSize="50"/>
<Border Background="Gray">
<Slider Minimum="10" Maximum="100" x:Name="slider" />
</Border>
</StackPanel>
</controls:PivotItem>
public MainPage()
{
...
this.slider.ManipulationStarted += new EventHandler<ManipulationStartedEventArgs>(slider_ManipulationStarted);
Touch.FrameReported += new TouchFrameEventHandler(Touch_FrameReported);
}
void Touch_FrameReported(object sender, TouchFrameEventArgs e)
{
if (e.GetPrimaryTouchPoint(this.slider).Action == TouchAction.Up)
{
myPivot.IsHitTestVisible = true;
}
}
void slider_ManipulationStarted(object sender, ManipulationStartedEventArgs e)
{
myPivot.IsHitTestVisible = false;
}
That`s it. You can get the full source code here.
I hope that the post was helpful.
You can also follow us on Twitter @winphonegeek
Comments
Publish app
posted by: Thicary Jahman on 3/25/2011 5:24:37 PM
Thank you for this post. I was wondering how to do this in my app. Now everything is clear so I am looking forward to submitting my app to the Marketplace pretty soon...
Not a good idea
posted by: jmguazzo on 3/30/2011 6:13:54 AM
Not such a good idea for me because by doing so you will break the "standard" behaviour. This sounds great because with this you can put a "bing maps control" in a pivot or panorama but this will lead to "strange" UI that some users won't understand or accept. If you develop just for yourself, then it's great ! If you intend to sell it/make money with it, you should think about all the other users. Some will understand your concept and agree with it, many others won't. The goal of WP7 is to have some constant design and behaviour accross all applications, like you wouldn't be able to tell "who" did it. Bypassing this may lead to an obscure patchwork of strange apps. Are you really, really, really sure you need to have a pivot that shouldn't flip ? Isn't there another design that may suit your needs ?
Very nice
posted by: Vikas Patidar on 9/30/2011 12:51:05 PM
Hi, thanks for sharing this and it is very useful. Also please make correction in spelling of FALSE.
worked well for me
posted by: Ramya on 1/31/2012 9:13:55 PM
hey, Thanks for sharing...i was thinking of changing my entire approach otherwise. It works well for me
Our Top Articles & Free books
- Our FREE e-book: "Windows Phone Toolkit In Depth" 2nd edition
- 400+ Windows Phone Development articles in our Article Index
- 21 WP7 Toolkit in Depth articles covering all controls
- 12 WP7 Coding4Fun Toolkit in Depth articles covering all controls
- Performance Tips when creating WP7 apps
- Creating a WP7 Custom Control in 7 Steps
- WP7 working with VisualStates: How to make a ToggleSwitch from CheckBox
- What makes a WP7 App successful
- Creating theme friendly UI in WP7 using OpacityMask
- Implementing Windows Phone 7 DataTemplateSelector and CustomDataTemplateSelector
- All about Splash Screens in WP7 – Creating animated Splash Screen
- Getting Started with Unit Testing in Silverlight for WP7
- WP7 WatermarkedTextBox custom control
Our Top Tips & Samples
- All about WP7 Isolated Storage series
- WP7 Dynamically Generating DataTemplate in code
- 5 tips for a successful WP7 Marketplace submission
- WP7: Navigating to a page in different assembly
- WP7 ContextMenu: answers to popular questions
- WP7 ListBox: answers to popular questions
- WP7 working with Images: Content vs Resource build action
- WP7 Element Binding samples
- WP7 working with XML: reading, filtering and databinding
- Drawing in WP7: #2 Drawing shapes with finger
- WP7 TextBox Light theme problems - the solution
- Changing the WP7 Panorama Background Image dynamically with Animation
