mirror of
https://github.com/chylex/Backup-Essentials.git
synced 2024-10-17 08:42:44 +02:00
55 lines
2.0 KiB
C#
55 lines
2.0 KiB
C#
using BackupEssentials.Utils;
|
|
using System;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Media;
|
|
using System.Windows.Threading;
|
|
|
|
namespace BackupEssentials.Controls{
|
|
public class ButtonMainMenu:Button{
|
|
public static readonly DependencyProperty ClickPageProperty = DependencyProperty.Register("ClickPage",typeof(string),typeof(ButtonMainMenu));
|
|
|
|
public string ClickPage {
|
|
get { return (string)base.GetValue(ClickPageProperty); }
|
|
set { base.SetValue(ClickPageProperty,(string)value); }
|
|
}
|
|
|
|
private bool IsCheckedVar;
|
|
|
|
public bool IsChecked {
|
|
get { return IsCheckedVar; }
|
|
set { IsCheckedVar = value; VisualStateManager.GoToState(this,IsCheckedVar ? "Pressed" : "Normal",true); }
|
|
}
|
|
|
|
public ButtonMainMenu(){
|
|
SizeChanged += (sender, args) => {
|
|
if (IsChecked)VisualStateManager.GoToState(this,"Pressed",false);
|
|
};
|
|
}
|
|
|
|
public override void OnApplyTemplate(){
|
|
if (!WindowsVersion.IsFullySupported())((Label)Template.FindName("label",this)).Effect = null;
|
|
|
|
base.OnApplyTemplate();
|
|
|
|
foreach(VisualStateGroup group in VisualStateManager.GetVisualStateGroups((FrameworkElement)Template.FindName("MainMenuButtonGrid",this))){
|
|
group.CurrentStateChanging += (sender, args) => {
|
|
if (IsChecked && !args.NewState.Name.Equals("Pressed")){
|
|
DispatcherTimer timer = new DispatcherTimer();
|
|
timer.Interval = new TimeSpan(1);
|
|
|
|
timer.Tick += (sender2, args2) => {
|
|
if (IsChecked){
|
|
VisualStateManager.GoToState(this,"Pressed",false);
|
|
timer.Stop();
|
|
}
|
|
};
|
|
|
|
timer.Start();
|
|
}
|
|
};
|
|
}
|
|
}
|
|
}
|
|
}
|