dotnet / dotnet/maui

Setting `Slider.Maximum` or `Slider.Minimum` resets binding of `Slider.Value`

Open
#12,285 5 comments 6 reactions 0 assignees View on GitHub
area-controls-slider platform/android platform/ios platform/macos platform/windows s/triaged s/verified t/bug
Dominant language
C#
Stars
23.3k
Forks
2k
Avg merge
1d 14h
Merged PRs (30d)
296

Description

### Description

I have the following situation. My `MediaElement` I'm implementing in the .NET MAUI Community Toolkit has to properties:

```csharp
public TimeSpan Position { get; }
public TimeSpan Duration { get; }
```

Then I add a `Slider` in the consuming application like this:

```xml

```

When I set it up like this, changes in `MediaElement.Position` will not update `Slider.Value`.

A couple of observations:
* When I remove `Mode=OneWay` from the `Value` binding, it works, however I will end up having warnings in the application output and operating the slider is glitchy
* When `MediaElement.Position` is also settable, it starts working, but that shouldn't be the solution. For reasons I can't make it settable
* When I set `Slider.Maximum` to a hardcoded value it starts working

So somewhere the binding goes wrong. Talking to @StephaneDelcroix he mentioned

> setting the Max sets the Value, that might remove a binding
> instead of doing slider.Value = foo, it should call SetValueCore() with the right flags to not remove bindings
> so when you bind the Max, you should reapply the Value Binding

This seems to be referring to
* https://github.com/dotnet/maui/blob/main/src/Controls/src/Core/Slider.cs#L14
* https://github.com/dotnet/maui/blob/main/src/Controls/src/Core/Slider.cs#L22
* https://github.com/dotnet/maui/blob/main/src/Controls/src/Core/Slider.cs#L79

Where `Value` gets set without respecting any binding that might be in place.

### Steps to Reproduce

See above and/or check the .NET MAUI Community Toolkit sample here: https://github.com/CommunityToolkit/Maui/blob/e9551695eeea516ba2e8a24399965dbb2996b6ab/samples/CommunityToolkit.Maui.Sample/Pages/Views/MediaElementPage.xaml#L62-L67

### Link to public reproduction project repository

https://github.com/CommunityToolkit/Maui/blob/e9551695eeea516ba2e8a24399965dbb2996b6ab/samples/CommunityToolkit.Maui.Sample/Pages/Views/MediaElementPage.xaml#L62-L67

### Version with bug

7.0 (current)

### Last version that worked well

Unknown/Other

### Affected platforms

iOS, Android, Windows, macOS, Other (Tizen, Linux, etc. not supported by Microsoft directly)

### Affected platform versions

This is a core issue, not specific to any platform

### Did you find any workaround?

Implement a custom binding that updates the slider property values.

### Relevant log output

_No response_

Contributor guide

Open the contributing guide

Research direction

Start with the referenced Slider.cs locations at lines 14, 22, and 79, where Maximum or Minimum changes Value, then inspect how those assignments interact with the existing Value binding. Use the MediaElement sample linked in the issue to reproduce the behavior and verify that Position updates continue reaching Slider.Value while the bound Maximum changes.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.