Browse Source

Fix ToggleButton tests

pull/9607/head
robloo 4 years ago
parent
commit
0bb1b2ec03
  1. 47
      src/Avalonia.Controls/Primitives/ToggleButton.cs

47
src/Avalonia.Controls/Primitives/ToggleButton.cs

@ -68,7 +68,6 @@ namespace Avalonia.Controls.Primitives
static ToggleButton() static ToggleButton()
{ {
IsCheckedProperty.Changed.AddClassHandler<ToggleButton>((x, e) => x.OnIsCheckedChanged(e));
} }
public ToggleButton() public ToggleButton()
@ -176,6 +175,7 @@ namespace Avalonia.Controls.Primitives
/// Called when <see cref="IsChecked"/> becomes true. /// Called when <see cref="IsChecked"/> becomes true.
/// </summary> /// </summary>
/// <param name="e">Event arguments for the routed event that is raised by the default implementation of this method.</param> /// <param name="e">Event arguments for the routed event that is raised by the default implementation of this method.</param>
[Obsolete("Use OnIsCheckedChanged instead.")]
protected virtual void OnChecked(RoutedEventArgs e) protected virtual void OnChecked(RoutedEventArgs e)
{ {
RaiseEvent(e); RaiseEvent(e);
@ -185,6 +185,7 @@ namespace Avalonia.Controls.Primitives
/// Called when <see cref="IsChecked"/> becomes false. /// Called when <see cref="IsChecked"/> becomes false.
/// </summary> /// </summary>
/// <param name="e">Event arguments for the routed event that is raised by the default implementation of this method.</param> /// <param name="e">Event arguments for the routed event that is raised by the default implementation of this method.</param>
[Obsolete("Use OnIsCheckedChanged instead.")]
protected virtual void OnUnchecked(RoutedEventArgs e) protected virtual void OnUnchecked(RoutedEventArgs e)
{ {
RaiseEvent(e); RaiseEvent(e);
@ -194,31 +195,51 @@ namespace Avalonia.Controls.Primitives
/// Called when <see cref="IsChecked"/> becomes null. /// Called when <see cref="IsChecked"/> becomes null.
/// </summary> /// </summary>
/// <param name="e">Event arguments for the routed event that is raised by the default implementation of this method.</param> /// <param name="e">Event arguments for the routed event that is raised by the default implementation of this method.</param>
[Obsolete("Use OnIsCheckedChanged instead.")]
protected virtual void OnIndeterminate(RoutedEventArgs e) protected virtual void OnIndeterminate(RoutedEventArgs e)
{ {
RaiseEvent(e); RaiseEvent(e);
} }
/// <summary>
/// Called when <see cref="IsChecked"/> changes.
/// </summary>
/// <param name="e">Event arguments for the routed event that is raised by the default implementation of this method.</param>
protected virtual void OnIsCheckedChanged(RoutedEventArgs e)
{
RaiseEvent(e);
}
protected override AutomationPeer OnCreateAutomationPeer() protected override AutomationPeer OnCreateAutomationPeer()
{ {
return new ToggleButtonAutomationPeer(this); return new ToggleButtonAutomationPeer(this);
} }
private void OnIsCheckedChanged(AvaloniaPropertyChangedEventArgs e) /// <inheritdoc/>
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
{ {
var newValue = (bool?)e.NewValue; base.OnPropertyChanged(change);
switch (newValue) if (change.Property == IsCheckedProperty)
{ {
case true: var newValue = change.GetNewValue<bool?>();
OnChecked(new RoutedEventArgs(IsCheckedChangedEvent));
break; #pragma warning disable CS0618 // Type or member is obsolete
case false: switch (newValue)
OnUnchecked(new RoutedEventArgs(IsCheckedChangedEvent)); {
break; case true:
default: OnChecked(new RoutedEventArgs(CheckedEvent));
OnIndeterminate(new RoutedEventArgs(IsCheckedChangedEvent)); break;
break; case false:
OnUnchecked(new RoutedEventArgs(UncheckedEvent));
break;
default:
OnIndeterminate(new RoutedEventArgs(IndeterminateEvent));
break;
}
#pragma warning restore CS0618 // Type or member is obsolete
OnIsCheckedChanged(new RoutedEventArgs(IsCheckedChangedEvent));
} }
} }

Loading…
Cancel
Save