Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8286305
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T11:41:56+00:00 2026-06-08T11:41:56+00:00

I want to have a slider that returns to 0 when the user stops

  • 0

I want to have a slider that returns to 0 when the user stops dragging.

So far I have this:

<Window x:Class="CenteredSliderTest.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="350" Width="525">
<DockPanel>
    <!--Value="{Binding ZSpeed}"-->
    <Slider DockPanel.Dock="Left"
                                x:Name="ZSlider"
                                Minimum="-100" Maximum="100"
                                SelectionStart="-20" SelectionEnd="20"
                                Orientation="Vertical" 
                                TickFrequency="10" 
                                TickPlacement="TopLeft" 
                                AutoToolTipPlacement="TopLeft"
                                AutoToolTipPrecision="2"
                                LargeChange="10"
                                SmallChange="1"
                                IsDirectionReversed="True"
                                Focusable="False"
                                >
        <Slider.Triggers>
            <EventTrigger RoutedEvent="LostMouseCapture" SourceName="ZSlider">
                <EventTrigger.Actions>
                    <BeginStoryboard>
                        <Storyboard>
                            <DoubleAnimation
                                Storyboard.TargetName="ZSlider"
                                Storyboard.TargetProperty="Value"
                                From="{Binding Value, ElementName=ZSlider}"
                                To="0.0"
                                Duration="0:0:1.5"
                                FillBehavior="Stop"
                                />
                        </Storyboard>
                    </BeginStoryboard>
                </EventTrigger.Actions>

            </EventTrigger>
        </Slider.Triggers>
    </Slider>
    <TextBlock Text="{Binding ZSpeed}" />
</DockPanel>
</Window>

This works as long as I don’t bind the slider value to my DependencyProperty ZSpeed.

As soon as I do this, the slider jumps back to the original value and at the second attempt the slider can’t be dragged anymore.

So what can I do (preferable in xaml) in order to get the animation modify not only the slider but also the ZSpeed property?

EDIT

Code in MainWindow:

    public partial class MainWindow : Window
{


    public double ZSpeed
    {
        get { return (double)GetValue(ZSpeedProperty); }
        set { SetValue(ZSpeedProperty, value); }
    }

    // Using a DependencyProperty as the backing store for ZSpeed.  This enables animation, styling, binding, etc...
    public static readonly DependencyProperty ZSpeedProperty =
        DependencyProperty.Register("ZSpeed", typeof(double), typeof(MainWindow), new UIPropertyMetadata(0.0));



    public MainWindow()
    {
        InitializeComponent();
        this.DataContext = this;

        Binding binding = new Binding("Value") { Source = ZSlider }; 
        this.SetBinding(ZSpeedProperty, binding); 
    }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T11:42:00+00:00Added an answer on June 8, 2026 at 11:42 am

    You might reverse the direction of the binding. Instead of binding the Slider’s Value to ZSpeed you could bind ZSpeed to Value. This would also be the “natural” binding direction if the Slider is meant to change ZSpeed, but ZSpeed won’t change otherwise.

    EDIT: If ZSpeed is a dependency property in some data class MyData you could create a binding in code like this:

    MyData dataObject = ...
    Binding binding = new Binding("Value") { Source = ZSlider };
    dataObject.SetBinding(MyData.ZSpeedProperty, binding);
    

    SECOND EDIT: Picking up Daniels suggestion, you might animate ZSpeed instead of the Slider’s Value. Bind the Value to ZSpeed as before, remove the EventTrigger and add an event handler for LostMouseCapture:

    <Slider x:Name="ZSlider" ...
            Value="{Binding ZSpeed}"
            LostMouseCapture="ZSlider_LostMouseCapture"/>
    

    Code behind:

    private void ZSlider_LostMouseCapture(object sender, MouseEventArgs e)
    {
        DoubleAnimation animation = new DoubleAnimation
        {
            From = ZSpeed,
            To = 0d,
            Duration = TimeSpan.FromSeconds(1.5 * Math.Abs(ZSpeed) / 100d),
            FillBehavior = FillBehavior.Stop
        };
        ZSpeed = 0d;
        BeginAnimation(ZSpeedProperty, animation);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a slider that returns values from 0.0f to 1.0f. I want to
I'm modifying the jquery ui slider. I have certain stops I want the user
I want to make a GUI have a slider, this slider's value will be
I have an image slider plugin that I've made that I want to extend
I have a slider on my page. What I want to do is, to
I have a slider with 3 slides - Intro, Question, Submit. Now I want
i have a jquery slider function and i want to customize it. my requirement
I have a UITextView and I want have two buttons. When the user taps
I currently have a scrolling anchor animation that also adds an active class to
I have the following piece of jquery. Which basically is a content slider, that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.