/// <summary> /// Initializes a new instance of the MainViewModel class. /// </summary> public MainViewModel() { ////if (IsInDesignMode) ////{ //// // Code runs in Blend --> create design time data. ////} ////else ////{ //// // Code runs "for real" ////} /// RunAutomaticCommand = new ReactiveCommand(); RunAutomaticCommand.Subscribe(_ => { if (IsRunning.Value) { ShouldStop.Value = true; } else { Execute(); } }); TapOnceCommand = new ReactiveCommand(); TapOnceCommand.Subscribe(_ => TapOnce()); StartButtonText = IsRunning.Select(x => (x ? "Stop" : "Start")).ToReactiveProperty(); SearchAdbExec(); AdbInit(); SearchDevices(); }
public MainViewModel() { // ファイルから読む体で userDict.Add("111", new UserModel("111", "社会人P") { Color = Colors.LightGreen }); userDict.Add("222", new UserModel("222", "八百屋")); Comments = model.Comments.ToReadOnlyReactiveCollection(comment => { if (!userDict.TryGetValue(comment.ID, out var user)) { user = new UserModel(comment.ID); userDict.Add(user.ID, user); } return(new CommentViewModel(comment, user)); }).AddTo(disposable); #region Command NameChangeCommand.Subscribe(obj => { var menuItem = obj as MenuItem; var comment = menuItem.DataContext as CommentViewModel; var ib = new InputBox { DataContext = comment, Text = comment.Name.Value, }; if (ib.ShowDialog() == true) { comment.Name.Value = ib.Text; } }); ColorChangeCommand.Subscribe(obj => { var menuItem = obj as MenuItem; var comment = menuItem.DataContext as CommentViewModel; comment.Color.Value = (Color)menuItem.Tag; }); ConnectCommand = IsRunning.Select(x => !x).ToAsyncReactiveCommand(); ConnectCommand.Subscribe(async _ => { await model.ConnectAsync("lv1234567"); IsRunning.Value = true; }).AddTo(disposable); DisconnectCommand = IsRunning.ToReactiveCommand(); DisconnectCommand.Subscribe(_ => { model.Disconnect(); IsRunning.Value = false; }).AddTo(disposable); #endregion ConnectCommand.Execute(); }