0

I'm using the Surface SDK for the multitouch support. I needed to move 2 sliders at the same time...

I've created some SurfaceSlider, works well, except that the control do some inertia after the movement...

Is there a way to disable inertia? I've searched over the web and I didn't find anything... they don't offer an option or anything like that...

If you need more informations to solve my problem just tell me...

Thanks

UPDATE: I've tried to make my own slider like this, but it doesn't work...

public class WtoSurfaceSlider : SurfaceSlider
{

    #region " Ctors "
    static WtoSurfaceSlider()
    {
        // Override metadata with style defined in themes xaml
        DefaultStyleKeyProperty.OverrideMetadata(typeof(WtoSurfaceSlider), new FrameworkPropertyMetadata(typeof(WtoSurfaceSlider)));
    }

    public WtoSurfaceSlider()
    {
        Name = "New" + GetType().Name;
    }
    #endregion

    #region " Method "

    protected override void OnManipulationDelta(ManipulationDeltaEventArgs e)
    {
        if (e.IsInertial)
        {
            e.Complete();
            e.Handled = true;
        }
    }

    #endregion

}

EDIT

Finally, I found my answer with the comment of Eli Arbel. I declare my SurfaceSlider in a resource xaml file, so I don't have a .cs. So this works fine for me:

public class WtoSurfaceThumb : SurfaceThumb
{

    #region " Ctors "

    static WtoSurfaceThumb()
    {
        // Override metadata with style defined in themes xaml
        DefaultStyleKeyProperty.OverrideMetadata(typeof(WtoSurfaceThumb), new FrameworkPropertyMetadata(typeof(WtoSurfaceThumb)));
    }

    public WtoSurfaceThumb()
    {
        Name = "New" + GetType().Name;

        PreviewFlicked += new FlickEventHandler(WtoSurfaceThumb_PreviewFlicked);
    }

    #endregion

    #region " Method "

    private void WtoSurfaceThumb_PreviewFlicked(object sender, FlickEventArgs e)
    {
        e.Handled = true;
    }

    #endregion

}

And i replaced all the SurfaceThumb in my app by WtoSurfaceThumb.

Linus Juhlin
  • 1,175
  • 10
  • 31
mlemay
  • 1,622
  • 2
  • 32
  • 53

2 Answers2

2

You can use the following event:

<s:SurfaceSlider s:SurfaceThumb.PreviewFlicked="OnPreviewFlicked" />

And mark it as handled:

private void OnPreviewFlicked(object sender, FlickEventArgs e)
{
    e.Handled = true;
}

As a side note - you can use a normal slider if you don't need the flick functionality. Multi-touch is built into WPF 4.

Eli Arbel
  • 22,391
  • 3
  • 45
  • 71
  • I'll try this. But are you sure that the slider of WPF 4 can manage multitouch? I've tried a lot of things and I was never able to move 2 Slider at the same time, there is always one that takes all the input... – mlemay Apr 17 '12 at 10:43
  • I cannot write the first line, the s:SurfaceThumb doesn't exist in the same bracket of the SurfaceSlider (for me), the only "Surface" object that it allows me to put is SurfaceScrollViewer – mlemay Apr 17 '12 at 11:05
  • Yea thanks works great in a test app! But in my application, I define my SurfaceSlider in a Resource xaml file (and I cannot change it), so it doesn't have a .cs file associate with it... – mlemay Apr 17 '12 at 12:19
0

Add handlers to your sliders' OnManipulationDelta method...

How To Disable Inertia in ScatterView

http://msdn.microsoft.com/en-us/library/microsoft.surface.presentation.controls.surfaceslider.onmanipulationdelta.aspx

Community
  • 1
  • 1
Trent
  • 1,280
  • 11
  • 12
  • Do I need to create a class that inherit of the SurfaceSlider and just add the OnManipulationDelta? – mlemay Apr 16 '12 at 20:15
  • Assuming you have an instance, you should be able to pass an event to the event handler like the first link above. – Trent Apr 16 '12 at 20:55
  • I don't have an instance in my codebehind, and I don't want one, it's a generic code – mlemay Apr 16 '12 at 20:57
  • @Trent Have you tried that with SurfaceSlider? It doesn't work for me, and it seems like SurfaceSlider has kind of internal inertia calculation. At least i don't get any manipulation events, even with `IsManipulationEnabled="True"`. – Clemens Apr 16 '12 at 20:58
  • Sorry... I don't have working code. Just trying to help with what I can find. – Trent Apr 16 '12 at 20:59
  • @Clemens - are you setting the event handler on an instance or have you inherited the SurfaceSlider and overridden the method? – Trent Apr 16 '12 at 21:00
  • 1
    @Trent Added to a SurfaceSlider instance. And you should perhaps consider trying things out before posting answers. – Clemens Apr 16 '12 at 21:02
  • @Clemens, sorry. Just trying to be helpful. Not trying to claim I had it working. – Trent Apr 16 '12 at 21:19