Skip to content

Commit

Permalink
Made PART_Track optional for Slider (AvaloniaUI#14974)
Browse files Browse the repository at this point in the history
  • Loading branch information
TomEdwardsEnscape authored Mar 15, 2024
1 parent fd15b6b commit 1911955
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions src/Avalonia.Controls/Slider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public enum TickPlacement
/// </summary>
[TemplatePart("PART_DecreaseButton", typeof(Button))]
[TemplatePart("PART_IncreaseButton", typeof(Button))]
[TemplatePart("PART_Track", typeof(Track), IsRequired = true)]
[TemplatePart("PART_Track", typeof(Track))]
[PseudoClasses(":vertical", ":horizontal", ":pressed")]
public class Slider : RangeBase
{
Expand Down Expand Up @@ -203,22 +203,26 @@ protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
_increaseButtonReleaseDispose?.Dispose();
_pointerMovedDispose?.Dispose();

_decreaseButton = e.NameScope.Find<Button>("PART_DecreaseButton");
_track = e.NameScope.Get<Track>("PART_Track");
_increaseButton = e.NameScope.Find<Button>("PART_IncreaseButton");
_track = e.NameScope.Find<Track>("PART_Track");

_track.IgnoreThumbDrag = true;

if (_decreaseButton != null)
if (_track != null)
{
_decreaseButtonPressDispose = _decreaseButton.AddDisposableHandler(PointerPressedEvent, TrackPressed, RoutingStrategies.Tunnel);
_decreaseButtonReleaseDispose = _decreaseButton.AddDisposableHandler(PointerReleasedEvent, TrackReleased, RoutingStrategies.Tunnel);
}
_track.IgnoreThumbDrag = true;

if (_increaseButton != null)
{
_increaseButtonSubscription = _increaseButton.AddDisposableHandler(PointerPressedEvent, TrackPressed, RoutingStrategies.Tunnel);
_increaseButtonReleaseDispose = _increaseButton.AddDisposableHandler(PointerReleasedEvent, TrackReleased, RoutingStrategies.Tunnel);
_decreaseButton = e.NameScope.Find<Button>("PART_DecreaseButton");
_increaseButton = e.NameScope.Find<Button>("PART_IncreaseButton");

if (_decreaseButton != null)
{
_decreaseButtonPressDispose = _decreaseButton.AddDisposableHandler(PointerPressedEvent, TrackPressed, RoutingStrategies.Tunnel);
_decreaseButtonReleaseDispose = _decreaseButton.AddDisposableHandler(PointerReleasedEvent, TrackReleased, RoutingStrategies.Tunnel);
}

if (_increaseButton != null)
{
_increaseButtonSubscription = _increaseButton.AddDisposableHandler(PointerPressedEvent, TrackPressed, RoutingStrategies.Tunnel);
_increaseButtonReleaseDispose = _increaseButton.AddDisposableHandler(PointerReleasedEvent, TrackReleased, RoutingStrategies.Tunnel);
}
}

_pointerMovedDispose = this.AddDisposableHandler(PointerMovedEvent, TrackMoved, RoutingStrategies.Tunnel);
Expand Down

0 comments on commit 1911955

Please sign in to comment.