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.
42 lines
1.1 KiB
42 lines
1.1 KiB
// -----------------------------------------------------------------------
|
|
// <copyright file="ToggleButton.cs" company="Steven Kirk">
|
|
// Copyright 2014 MIT Licence. See licence.md for more information.
|
|
// </copyright>
|
|
// -----------------------------------------------------------------------
|
|
|
|
namespace Perspex.Controls.Primitives
|
|
{
|
|
using System;
|
|
using Perspex.Interactivity;
|
|
|
|
public class ToggleButton : Button
|
|
{
|
|
public static readonly PerspexProperty<bool> IsCheckedProperty =
|
|
PerspexProperty.Register<ToggleButton, bool>("IsChecked");
|
|
|
|
static ToggleButton()
|
|
{
|
|
Control.PseudoClass(IsCheckedProperty, ":checked");
|
|
}
|
|
|
|
public ToggleButton()
|
|
{
|
|
}
|
|
|
|
public bool IsChecked
|
|
{
|
|
get { return this.GetValue(IsCheckedProperty); }
|
|
set { this.SetValue(IsCheckedProperty, value); }
|
|
}
|
|
|
|
protected override void OnClick(RoutedEventArgs e)
|
|
{
|
|
this.Toggle();
|
|
}
|
|
|
|
protected virtual void Toggle()
|
|
{
|
|
this.IsChecked = !this.IsChecked;
|
|
}
|
|
}
|
|
}
|
|
|