using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using System.Threading.Tasks;
|
using System.Windows;
|
using System.Windows.Controls;
|
using System.Windows.Data;
|
using System.Windows.Documents;
|
using System.Windows.Input;
|
using System.Windows.Media;
|
using System.Windows.Media.Imaging;
|
using System.Windows.Navigation;
|
using System.Windows.Shapes;
|
|
namespace Bro.UI.Ctrls
|
{
|
/// <summary>
|
/// OperationCtrl.xaml 的交互逻辑
|
/// </summary>
|
public partial class OperationCtrl : UserControl
|
{
|
public OperationCtrl()
|
{
|
InitializeComponent();
|
}
|
|
public static readonly DependencyProperty IsRunningProperty;
|
public bool IsRunning
|
{
|
get => (bool)GetValue(IsRunningProperty);
|
set => SetValue(IsRunningProperty, value);
|
}
|
|
public static RoutedEvent RunEvent;
|
public static RoutedEvent StopEvent;
|
public static RoutedEvent LoadEvent;
|
|
public event RoutedEventHandler RunHandler
|
{
|
add { AddHandler(RunEvent, value); }
|
remove { RemoveHandler(RunEvent, value); }
|
}
|
|
public event RoutedEventHandler StopHandler
|
{
|
add { AddHandler(StopEvent, value); }
|
remove { RemoveHandler(StopEvent, value); }
|
}
|
|
public event RoutedEventHandler LoadHandler
|
{
|
add { AddHandler(LoadEvent, value); }
|
remove { RemoveHandler(LoadEvent, value); }
|
}
|
|
static OperationCtrl()
|
{
|
RunEvent = EventManager.RegisterRoutedEvent("RunHandler", RoutingStrategy.Direct, typeof(RoutedEventHandler), typeof(OperationCtrl));
|
StopEvent = EventManager.RegisterRoutedEvent("StopHandler", RoutingStrategy.Direct, typeof(RoutedEventHandler), typeof(OperationCtrl));
|
LoadEvent = EventManager.RegisterRoutedEvent("LoadHandler", RoutingStrategy.Direct, typeof(RoutedEventHandler), typeof(OperationCtrl));
|
|
IsRunningProperty = DependencyProperty.Register("IsRunning", typeof(bool), typeof(OperationCtrl), new PropertyMetadata(false, OnIsRunningPropertyChanged));
|
}
|
|
private static void OnIsRunningPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
{
|
OperationCtrl ctrl = d as OperationCtrl;
|
if (ctrl != null)
|
{
|
bool isRunning = (bool)e.NewValue;
|
ctrl.btnRun.IsChecked = isRunning;
|
ctrl.txtRun.Text = isRunning ? "停止" : "启动";
|
ctrl.icoRun.Kind = isRunning ? MahApps.Metro.IconPacks.PackIconFontAwesomeKind.StopSolid : MahApps.Metro.IconPacks.PackIconFontAwesomeKind.PlaySolid;
|
|
ctrl.btnLoad.IsEnabled = !isRunning;
|
|
if (isRunning)
|
{
|
ctrl.col1.Width = GridLength.Auto;
|
ctrl.btnLoad.Visibility = Visibility.Collapsed;
|
}
|
else
|
{
|
ctrl.col1.Width = new GridLength(1, GridUnitType.Star);
|
ctrl.btnLoad.Visibility = Visibility.Visible;
|
}
|
}
|
}
|
|
private void btnLoad_Click(object sender, RoutedEventArgs e)
|
{
|
RaiseEvent(new RoutedEventArgs(LoadEvent, this));
|
}
|
|
private void btnRun_Click(object sender, RoutedEventArgs e)
|
{
|
btnRun.IsChecked = !btnRun.IsChecked;
|
|
if (btnRun.IsChecked ?? true)
|
{
|
RaiseEvent(new RoutedEventArgs(StopEvent, this));
|
}
|
else
|
{
|
RaiseEvent(new RoutedEventArgs(RunEvent, this));
|
}
|
}
|
}
|
}
|