|
|
|
@ -8,31 +8,52 @@ using Avalonia.LogicalTree; |
|
|
|
namespace Avalonia.Controls |
|
|
|
{ |
|
|
|
/// <summary>
|
|
|
|
/// A WinUi like ToggleSwitch control.
|
|
|
|
/// A Toggle Switch control.
|
|
|
|
/// </summary>
|
|
|
|
///
|
|
|
|
|
|
|
|
public class ToggleSwitch : ToggleButton |
|
|
|
{ |
|
|
|
static ToggleSwitch() |
|
|
|
{ |
|
|
|
OffContentProperty.Changed.AddClassHandler<ToggleSwitch>((x, e) => x.OffContentChanged(e)); |
|
|
|
OnContentProperty.Changed.AddClassHandler<ToggleSwitch>((x, e) => x.OnContentChanged(e)); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Defines the <see cref="OffContent"/> property.
|
|
|
|
/// </summary>
|
|
|
|
public static readonly StyledProperty<object> OffContentProperty = |
|
|
|
AvaloniaProperty.Register<ToggleSwitch, object>(nameof(OffContent), defaultValue:"Off"); |
|
|
|
AvaloniaProperty.Register<ToggleSwitch, object>(nameof(OffContent), defaultValue: "Off"); |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Defines the <see cref="OffContentTemplate"/> property.
|
|
|
|
/// </summary>
|
|
|
|
public static readonly StyledProperty<IDataTemplate> OffContentTemplateProperty = |
|
|
|
AvaloniaProperty.Register<ToggleSwitch, IDataTemplate>(nameof(OffContentTemplate)); |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Defines the <see cref="OnContent"/> property.
|
|
|
|
/// </summary>
|
|
|
|
public static readonly StyledProperty<object> OnContentProperty = |
|
|
|
AvaloniaProperty.Register<ToggleSwitch, object>(nameof(OnContent), defaultValue: "On"); |
|
|
|
AvaloniaProperty.Register<ToggleSwitch, object>(nameof(OnContent), defaultValue: "On"); |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Defines the <see cref="OnContentTemplate"/> property.
|
|
|
|
/// </summary>
|
|
|
|
public static readonly StyledProperty<IDataTemplate> OnContentTemplateProperty = |
|
|
|
AvaloniaProperty.Register<ToggleSwitch, IDataTemplate>(nameof(OnContentTemplate)); |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets or Sets the Content that is displayed when in the On State.
|
|
|
|
/// </summary>
|
|
|
|
public object OnContent |
|
|
|
{ |
|
|
|
get { return GetValue(OnContentProperty); } |
|
|
|
set { SetValue(OnContentProperty, value); } |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets or Sets the Content that is displayed when in the Off State.
|
|
|
|
/// </summary>
|
|
|
|
public object OffContent |
|
|
|
{ |
|
|
|
get { return GetValue(OffContentProperty); } |
|
|
|
@ -51,13 +72,18 @@ namespace Avalonia.Controls |
|
|
|
private set; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets or Sets the <see cref="IDataTemplate"/> used to display the <see cref="OffContent"/>.
|
|
|
|
/// </summary>
|
|
|
|
public IDataTemplate OffContentTemplate |
|
|
|
{ |
|
|
|
get { return GetValue(OffContentTemplateProperty); } |
|
|
|
set { SetValue(OffContentTemplateProperty, value); } |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets or Sets the <see cref="IDataTemplate"/> used to display the <see cref="OnContent"/>.
|
|
|
|
/// </summary>
|
|
|
|
public IDataTemplate OnContentTemplate |
|
|
|
{ |
|
|
|
get { return GetValue(OnContentTemplateProperty); } |
|
|
|
@ -90,13 +116,6 @@ namespace Avalonia.Controls |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
static ToggleSwitch() |
|
|
|
{ |
|
|
|
OffContentProperty.Changed.AddClassHandler<ToggleSwitch>((x, e) => x.OffContentChanged(e)); |
|
|
|
OnContentProperty.Changed.AddClassHandler<ToggleSwitch>((x, e) => x.OnContentChanged(e)); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected override bool RegisterContentPresenter(IContentPresenter presenter) |
|
|
|
{ |
|
|
|
var result = base.RegisterContentPresenter(presenter); |
|
|
|
@ -114,6 +133,6 @@ namespace Avalonia.Controls |
|
|
|
|
|
|
|
return result; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|