csharpc-sharpdotnetxamlavaloniauicross-platformcross-platform-xamlavaloniaguimulti-platformuser-interfacedotnetcore
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
1.1 KiB
43 lines
1.1 KiB
// Copyright (c) The Perspex Project. All rights reserved.
|
|
// Licensed under the MIT license. See licence.md file in the project root for full license information.
|
|
|
|
using System;
|
|
using Perspex.Interactivity;
|
|
using Perspex.Data;
|
|
|
|
namespace Perspex.Controls.Primitives
|
|
{
|
|
public class ToggleButton : Button
|
|
{
|
|
public static readonly DirectProperty<ToggleButton, bool> IsCheckedProperty =
|
|
PerspexProperty.RegisterDirect<ToggleButton, bool>(
|
|
"IsChecked",
|
|
o => o.IsChecked,
|
|
(o,v) => o.IsChecked = v,
|
|
defaultBindingMode: BindingMode.TwoWay);
|
|
|
|
private bool _isChecked;
|
|
|
|
static ToggleButton()
|
|
{
|
|
PseudoClass(IsCheckedProperty, ":checked");
|
|
}
|
|
|
|
public bool IsChecked
|
|
{
|
|
get { return _isChecked; }
|
|
set { SetAndRaise(IsCheckedProperty, ref _isChecked, value); }
|
|
}
|
|
|
|
protected override void OnClick(RoutedEventArgs e)
|
|
{
|
|
Toggle();
|
|
base.OnClick(e);
|
|
}
|
|
|
|
protected virtual void Toggle()
|
|
{
|
|
IsChecked = !IsChecked;
|
|
}
|
|
}
|
|
}
|
|
|