microsoft-ui-xaml: Slider Tapped event doesn't always fire
Describe the bug When declaring a slider in XAML with a Tapped event, the resulting EventHandler doesn’t always get called when the slider is clicked/tapped.
Steps to reproduce the bug
- Create a new WInUI on UWP project
- Add the following XAML to
MainPage.xaml/MainWindow.xaml
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
<Slider Tapped="Slider_Tapped" Width="400"/>
<TextBlock x:Name="tb" Text="0 times tapped"/>
</StackPanel>
- Add the following code to
MainPage.xaml.cs/MainWindows.xaml.cs
private int timesTapped = 0;
private void Slider_Tapped(object sender, TappedRoutedEventArgs e)
{
timesTapped++;
tb.Text = String.Format("{0} times tapped", timesTapped);
}
- Run the project
- Start Tapping on the slider, on different positions of the track
- Notice the tap count doesn’t always get incremented.
Expected behavior
The Tapped event should be called with every click/tap on the slider.
Screenshots
Version Info
NuGet package version: WinUI 3 - Project Reunion 0.5 Preview: 0.5.0-prerelease
Windows app type:
| UWP | Win32 |
|---|---|
| Yes | Yes |
| Windows 10 version | Saw the problem? |
|---|---|
| Insider Build (xxxxx) | |
| October 2020 Update (19042) | Yes |
| May 2020 Update (19041) | |
| November 2019 Update (18363) | |
| May 2019 Update (18362) | |
| October 2018 Update (17763) | |
| April 2018 Update (17134) | |
| Fall Creators Update (16299) | |
| Creators Update (15063) |
| Device form factor | Saw the problem? |
|---|---|
| Desktop | Yes |
| Xbox | |
| Surface Hub | |
| IoT |
Additional context This issue also occurs on the old UWP API
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 1
- Comments: 15 (7 by maintainers)
Sorry about that. I can repro this easily. The track seems to be swallowing these events. Clicking on the track is not raising the event, but anywhere outside the track works.
@ranjeshj For what it’s worth, I think there is a legitimate bug here and I don’t think this issue should be closed out permanently as “not planned”. It’s very simple to repro this:
PointerPressed,PointerReleased, andTapped.Expected result: Every adjustment results in all three events being fired. Actual result: The events randomly don’t fire. The slider control eats them at random times.
This is basic functionality that developers should be able to rely on. IMO this needs to be fixed. Maybe it doesn’t have a high priority, but it’s definitely broken.
Why can’t
ValueChangedbe used instead? Because that tells you about value changes only and tells you nothing about manipulation. Here’s a concrete scenario: Imagine you have a slider where after the user stops dragging the slider around, you want to save the final value off to a database. You don’t want to do this during every single value change while the slider is being dragged around. You only want to do it after the slider has been released and the user has finalized their value selection.It should be very simple to do this. Listen for
PointerReleasedorTapped, and then commit the slider’s current value. Instead, the slider control is broken, and developers have to go to extravagant lengths to work around this bug.I think this is an interesting scenario that would be useful to support. We have a few similar cases in the platform where this works well such as ScrollViewerViewChangedEventArgs has a bool IsIntermediate property to allow one to determine if a particular instance of the event being raised is an intermediate event or a final event. I have filed an internal work item on our backlog to add support for this. This work will be triaged relative to other work so it will likely not be available in the near future.
Could you help me understand the issue and why ValueChanged event cannot be used to know when the value changes? Doing this for all input would mean handling it for touch (tapped), mouse (pointer), keyboard etc… ValueChanged would be a simpler way to handle it. The only case would be when the value changes through the data model, but that might be easier to figure out/exclude since the app is doing that maybe?