123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.Linq;
- using System.Runtime.Serialization;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Controls.Primitives;
- 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;
- using Aitex.Core.UI.MVVM;
- using MECF.Framework.Common.CommonData;
- using MECF.Framework.Common.Communications;
- using MECF.Framework.Common.IOCore;
- namespace EfemRT.Backends
- {
- /// <summary>
- /// ConnectionView.xaml 的交互逻辑
- /// </summary>
- public partial class ConnectionView : UserControl
- {
- public ConnectionView()
- {
- InitializeComponent();
- DataContext = new ConnectionViewModel();
- this.IsVisibleChanged += IOView_IsVisibleChanged;
- }
- private void IOView_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
- {
-
- (DataContext as TimerViewModelBase).EnableTimer(IsVisible);
- }
- }
- public class ConnectionViewModel : TimerViewModelBase
- {
- Random _rd = new Random();
- public ObservableCollection<NotifiableConnectionItem> ListConnections { get; set; }
-
- public ICommand ConnectCommand { get; set; }
- public ConnectionViewModel() : base(nameof(ConnectionViewModel))
- {
- ListConnections = new ObservableCollection<NotifiableConnectionItem>();
- ConnectCommand = new DelegateCommand<string>(DoConnect);
- }
- private void DoConnect(string obj)
- {
- ConnectionManager.Instance.Connect(obj);
- }
- protected override void Poll()
- {
- Application.Current.Dispatcher.Invoke(new Action(() =>
- {
- foreach (var item in ConnectionManager.Instance.ConnectionList)
- {
- if (ListConnections.Count == 0 || (ListConnections.FirstOrDefault(x => x.Name == item.Name)==null))
- {
- ListConnections.Add(item);
- }
- else
- {
- var find = ListConnections.First(x => x.Name == item.Name);
- find.IsConnected = find.IsConnected;
- find.InvokePropertyChanged("IsConnected");
- }
- }
- InvokePropertyChanged("ListConnections");
- }));
- }
- }
- public class IoButton : ToggleButton
- {
- public static readonly DependencyProperty ONProperty;
- static IoButton()
- {
- ONProperty = DependencyProperty.Register("ON", typeof(bool), typeof(IoButton));
- }
- public bool ON
- {
- get { return (bool)GetValue(ONProperty); }
- set { SetValue(ONProperty, value); }
- }
- }
- public class BoolBackgroundConverter : IValueConverter
- {
- public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
- {
- bool? ret = (bool?)value;
- return ret.HasValue && ret.Value ? "LightBlue" : "Transparent";
- }
- public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
- {
- return null;
- }
- }
- }
|