dotnet/wpf · error · NotSupportedException
SR.Track_SameButtons
Error message
SR.Track_SameButtons
What it means
Track.DecreaseButton setter throws NotSupportedException when the value being assigned is the same object already stored in IncreaseButton. A Track must never use one Button for both the increase and decrease repeat buttons, so the assignment is rejected before UpdateComponent runs.
Solutions
- Provide two distinct Button instances (or two distinct template parts) for DecreaseButton and IncreaseButton.
- In a custom template, define two separate RepeatButton parts with different names/styles and bind each to its Track property.
- If one visual style is desired, duplicate the element with shared style rather than sharing the instance.
Example fix
// before
<Track.DecreaseButton>
<RepeatButton x:Name="btn" Command="ScrollBar.DecreaseSmall"/>
</Track.DecreaseButton>
<Track.IncreaseButton>
<RepeatButton Command="{Binding Command, ElementName=btn}"/> <!-- same instance pattern -> throws when identical -->
</Track.IncreaseButton>
// after
<Track.DecreaseButton>
<RepeatButton Command="ScrollBar.DecreaseSmall"/>
</Track.DecreaseButton>
<Track.IncreaseButton>
<RepeatButton Command="ScrollBar.IncreaseSmall"/> <!-- distinct instance -->
</Track.IncreaseButton> Defensive patterns
Strategy: validation
Validate before calling
if (newButton != null && !ReferenceEquals(newButton, track.IncreaseButton)) track.DecreaseButton = newButton;
Type guard
static bool CanSetDecreaseButton(Track track, Button value) => value == null || !ReferenceEquals(track.IncreaseButton, value);
Try / catch
try
{
track.DecreaseButton = value;
}
catch (NotSupportedException)
{
// same instance as IncreaseButton; create a distinct button
} Prevention
- Always create two distinct button instances for a Track
- Never share one part name between Decrease/Increase bindings
- Use separate styles instead of shared instances for identical visuals
When it happens
Trigger: x:Name-ing or assigning the same Button instance (or template-resolved reference) to both DecreaseButton and IncreaseButton on a Track, typically via a custom ScrollBar/Slider template that reuses one button element.
Common situations: Minimal custom ScrollBar templates where a developer gives both repeat-button slots the same named part; code-behind that wires one button object to both properties.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- By default, ToolTip property does not support ToolTip…
- Cannot convert from type.
- Cannot convert to type.
- Cannot convert to type.
- CollectionIsFixedSize
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/5f2807562e6c6b87.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/Track.cs:164
InvalidateMeasure();
InvalidateArrange();
}
}
/// <summary>
/// The RepeatButton used to decrease the Value
/// </summary>
public RepeatButton DecreaseRepeatButton
{
get
{
return _decreaseButton;
}
set
{
if (_increaseButton == value)
{
throw new NotSupportedException(SR.Track_SameButtons);
}
UpdateComponent(_decreaseButton, value);
_decreaseButton = value;
if (_decreaseButton != null)
{
CommandManager.InvalidateRequerySuggested(); // Should post an idle queue item to update IsEnabled on button
}
}
}
/// <summary>
/// The Thumb in the Track
/// </summary>
public Thumb Thumb
{
get
{View on GitHub (pinned to 81131a70a4)