-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
efeb62a
commit 3186d1b
Showing
7 changed files
with
72 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using System.Windows; | ||
using System.Windows.Controls; | ||
using System.Windows.Media; | ||
|
||
namespace MFATools.Controls; | ||
|
||
public class PinButton : Button | ||
{ | ||
public static readonly DependencyProperty IsCheckedProperty = | ||
DependencyProperty.Register(nameof(IsChecked), typeof(bool), typeof(PinButton), | ||
new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, | ||
OnIsCheckedChanged)); | ||
|
||
public bool IsChecked | ||
{ | ||
get => (bool)GetValue(IsCheckedProperty); | ||
set => SetValue(IsCheckedProperty, value); | ||
} | ||
|
||
public event RoutedPropertyChangedEventHandler<bool> CheckedChanged; | ||
|
||
private static void OnIsCheckedChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) | ||
{ | ||
if (d is PinButton pinButton) | ||
{ | ||
pinButton.OnCheckedChanged(pinButton.IsChecked, (bool)e.NewValue); | ||
} | ||
} | ||
|
||
private void OnCheckedChanged(bool oldValue, bool newValue) | ||
{ | ||
CheckedChanged?.Invoke(this, new RoutedPropertyChangedEventArgs<bool>(oldValue, newValue)); | ||
} | ||
|
||
static PinButton() | ||
{ | ||
DefaultStyleKeyProperty.OverrideMetadata(typeof(PinButton), new FrameworkPropertyMetadata(typeof(PinButton))); | ||
} | ||
|
||
// Constructor | ||
public PinButton() | ||
{ | ||
// Set the default content to 📌 | ||
Content = "📌"; | ||
Click += (_, _) => { IsChecked = !IsChecked; }; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters