public MyViewModel(MyModel model) { _model = model; _statusPropertyChangedProxy = new PropertyChangedProxy <MyModel, string>( _model, myModel => myModel.Status, s => OnPropertyChanged("Status") ); }
public MainViewModel(MainModel model) { _model = model; Jobs = new ObservableCollection <JobInfoViewModel>(); var dispatcher = Dispatcher.CurrentDispatcher; model.Client.JobAddedEvent += (sender, args) => { dispatcher.Invoke(DispatcherPriority.DataBind, new Action( () => Jobs.Add(new JobInfoViewModel(args.ClientJob)))); }; model.Client.JobRemovedEvent += (sender, args) => { dispatcher.Invoke(DispatcherPriority.DataBind, new Action( () => Jobs.Remove(new JobInfoViewModel(args.ClientJob)))); }; _statusPropertyChangedProxy = new PropertyChangedProxy <ClientBase, ClientStatusType>(_model.Client, m => m.Status, newValue => { OnPropertyChanged(() => Status); OnPropertyChanged(() => IsStarted); OnPropertyChanged(() => IsStopped); }); // Initialize the network adapters NetworkAdapters = new ObservableCollection <string>(_model.NetworkAnalyzer.GetNetworkAdapters()); SelectedNetworkAdapter = NetworkAdapters[0]; // Initialize commands ShowSettingsCommand = new RelayCommand(o => { const string settingsFile = "settings.json"; Process.Start("notepad.exe", settingsFile); }); AddSingleJobCommand = new RelayCommand(o => model.Client.ManuallyStartJob()); StartCommand = new RelayCommand(o => model.Client.StartProcessing()); StopCommand = new RelayCommand(o => model.Client.StopProcessing()); // Initialize run-time only timer to update the display of some values if (LicenseManager.UsageMode != LicenseUsageMode.Designtime) { var timer = new DispatcherTimer { Interval = TimeSpan.FromMilliseconds(500) }; timer.Tick += (sender, args) => { foreach (var job in Jobs) { job.RefreshDuration(); } }; timer.Tick += (sender, args) => { OnPropertyChanged(() => TrafficIn); OnPropertyChanged(() => TrafficOut); }; timer.Start(); } }
public JobInfoViewModel(ClientJob clientJob) { _clientJob = clientJob; StartDate = DateTime.Now; JobInput = clientJob.Job.GetInput(); _statusPropertyChangedProxy = new PropertyChangedProxy <ClientJob, string>(clientJob, m => m.HandlerName, newValue => { OnPropertyChanged(() => HandlerName); }); }
public TypedBinding(Func <TSource, TProperty> getter, Action <TSource, TProperty> setter, Tuple <Func <TSource, object>, string> [] handlers) { _getter = getter ?? throw new ArgumentNullException(nameof(getter)); _setter = setter; if (handlers == null) { return; } _handlers = new PropertyChangedProxy [handlers.Length]; for (var i = 0; i < handlers.Length; i++) { _handlers [i] = new PropertyChangedProxy(handlers [i].Item1, handlers [i].Item2, this); } }
/// <summary> /// MainWindowのViewModelを初期化します。 /// </summary> public MainWindowViewModel() { //キーボード入力取得クラスのインスタンスを生成・イベントハンドラーの設定 this.KeyboardUtil = new Models.KeyboardUtil(this); this.KeyboardUtil.KeyHookKeyUp += this.KeyHookKeyUp_Handler; this.KeyboardUtil.KeyHookKeyDown += this.KeyHookKeyDown_Handler; this.KeyboardUtil.KeyHookShiftKeyUp += this.KeyHookShiftKeyUp_Handler; this.KeyboardUtil.KeyHookShiftKeyDown += this.KeyHookShiftKeyDown_Handler; this.KeyboardUtil.KeyHookAltKeyUp += this.KeyHookAltKeyUp_Handler; this.KeyboardUtil.KeyHookAltKeyDown += this.KeyHookAltKeyDown_Handler; //設定ファイル SettingsModel = new AppSettingsModel(); //キーボード入力表示クラスのインスタンスを生成・プロパティの割当 KeyboardDisplay = new KeyBoardDisplay(SettingsModel.SelectedSkinSettingFilePath, 1D); //設定ファイルのパスを与えて初期化 KeyDisplayInfoCollection = KeyboardDisplay.KeyDisplayInfoCollection; //キー入力統計情報 KeyInputStatistics = new KeyInputStatistics(); this.KeyboardUtil.KeyHookKeyDown += KeyInputStatistics.KeyDownCount; this.KeyboardUtil.KeyHookShiftKeyDown += KeyInputStatistics.KeyDownCount; this.KeyboardUtil.KeyHookAltKeyDown += KeyInputStatistics.KeyDownCount; MainWindowViewModel vm = this; _keyInputPropertyChanged = new PropertyChangedProxy <KeyInputStatistics, string>( KeyInputStatistics, keyStatic => keyStatic.ElapsedTimeString, elapsedTime => vm.OnPropertyChanged(nameof(elapsedTime)) ); _keyInputPropertyChangedKeyDownSum = new PropertyChangedProxy <KeyInputStatistics, int>( KeyInputStatistics, keyStatic => keyStatic.KeyDownSum, KeyDownSum => vm.OnPropertyChanged(nameof(KeyDownSum)) ); _keyInputPropertyChangedCurrentKPM = new PropertyChangedProxy <KeyInputStatistics, double>( KeyInputStatistics, keyStatic => keyStatic.CurrentKPM, CurrentKPM => vm.OnPropertyChanged(nameof(CurrentKPM)) ); _keyInputPropertyChangedMaxKPM = new PropertyChangedProxy <KeyInputStatistics, double>( KeyInputStatistics, keyStatic => keyStatic.MaxKPM, MaxKPM => vm.OnPropertyChanged(nameof(MaxKPM)) ); //_baseKeyBoardPicChanged = new PropertyChangedProxy<AppSettingsModel, string>( // SettingsModel, // setting => setting.SelectedSkinBaseKeyboardPicFilePath, // SelectedSkinBaseKeyboardPicFilePath => vm.OnPropertyChanged(nameof(SelectedSkinBaseKeyboardPicFilePath)) //); //最初の入力にセパレータは不要 this.IsInsertSeparatorSymbol = false; //Shiftキー初期化 this.IsShiftPressed = false; //バージョン情報を取得し、タイトルへ反映する this.TitleString = Models.General.GetTitleString(); ClearInput = new ClearInput_Imp(this); OpenOption = new OpenOption(this); WindowClose = new MenuCloseButtonInput(this); SettingsModel.PropertyChanged += SettingsModel_PropertyChanged; }