public LiveRecordListView(LiveRecordListViewModel viewModel) { InitializeComponent(); ViewModel = viewModel; this.WhenActivated(d => { this.Bind(ViewModel, vm => vm.Config.RoomId, v => v.RoomIdTextBox.Text, x => $@"{x}", x => long.TryParse(x, out var v) ? v : 732).DisposeWith(d); RoomIdTextBox.Events().KeyUp.Subscribe(args => { if (args.Key == Key.Enter) { ViewModel.TriggerLiveRecordListQuery = !ViewModel.TriggerLiveRecordListQuery; } }).DisposeWith(d); this.OneWayBind(ViewModel, vm => vm.ImageUri, v => v.FaceImage.Source, url => url is null ? null : new BitmapImage(new Uri(url))).DisposeWith(d); this.OneWayBind(ViewModel, vm => vm.Name, v => v.NameTextBlock.Text).DisposeWith(d); this.OneWayBind(ViewModel, vm => vm.Uid, v => v.UIdTextBlock.Text, i => $@"UID: {i}").DisposeWith(d); this.OneWayBind(ViewModel, vm => vm.Level, v => v.LvTextBlock.Text, i => $@"Lv{i}").DisposeWith(d); this.OneWayBind(ViewModel, vm => vm.RoomId, v => v.RoomIdTextBlock.Text, i => $@"房间号: {i}").DisposeWith(d); this.OneWayBind(ViewModel, vm => vm.ShortRoomId, v => v.ShortRoomIdTextBlock.Text, i => $@"短号: {i}").DisposeWith(d); this.OneWayBind(ViewModel, vm => vm.RecordCount, v => v.RecordCountTextBlock.Text, i => $@"列表总数: {i}").DisposeWith(d); this.OneWayBind(ViewModel, vm => vm.IsLiveRecordBusy, v => v.LiveRecordBusyIndicator.IsActive).DisposeWith(d); this.OneWayBind(ViewModel, vm => vm.LiveRecordList, v => v.LiveRecordListDataGrid.ItemsSource).DisposeWith(d); var selectedItems = this.WhenAnyValue(v => v.LiveRecordListDataGrid.SelectedItems); var selectedItem = this.WhenAnyValue(v => v.LiveRecordListDataGrid.SelectedItem); this.BindCommand(ViewModel, vm => vm.DownLoadVideoCommand, v => v.DownLoadVideoMenuItem, selectedItems).DisposeWith(d); this.BindCommand(ViewModel, vm => vm.DownLoadDanmuCommand, v => v.DownLoadDanmuMenuItem, selectedItems).DisposeWith(d); this.BindCommand(ViewModel, vm => vm.CopyLiveRecordDownloadUrlCommand, v => v.CopyLiveRecordDownloadUrlMenuItem, selectedItem).DisposeWith(d); this.BindCommand(ViewModel, vm => vm.OpenDirCommand, v => v.OpenDirMenuItem, selectedItem).DisposeWith(d); this.BindCommand(ViewModel, vm => vm.OpenLiveRecordUrlCommand, v => v.OpenLiveRecordUrlMenuItem, selectedItem).DisposeWith(d); }); }
public MainWindow( MainWindowViewModel viewModel, LiveRecordListViewModel liveRecordList, TaskListViewModel taskList, LogViewModel log, SettingViewModel settings, StreamRecordViewModel streamRecord, UserSettingsViewModel userSettings, FFmpegCommandViewModel ffmpegCommand) { InitializeComponent(); ViewModel = viewModel; this.WhenActivated(d => { this.BindCommand(ViewModel, vm => vm.ShowWindowCommand, v => v.NotifyIcon, nameof(NotifyIcon.TrayLeftMouseUp)).DisposeWith(d); this.BindCommand(ViewModel, vm => vm.ShowWindowCommand, v => v.ShowMenuItem).DisposeWith(d); this.BindCommand(ViewModel, vm => vm.ExitCommand, v => v.ExitMenuItem).DisposeWith(d); this.Bind(ViewModel, vm => vm.Router, v => v.RoutedViewHost.Router).DisposeWith(d); Observable.FromEventPattern <NavigationViewSelectionChangedEventArgs>(NavigationView, nameof(NavigationView.SelectionChanged)) .Subscribe(args => { if (args.EventArgs.IsSettingsSelected) { ViewModel.Router.Navigate.Execute(settings); return; } if (args.EventArgs.SelectedItem is not NavigationViewItem { Tag: string tag }) { return; } switch (tag) { case @"1": { ViewModel.Router.Navigate.Execute(liveRecordList); break; } case @"2": { ViewModel.Router.Navigate.Execute(taskList); break; } case @"3": { ViewModel.Router.Navigate.Execute(log); break; } case @"4": { ViewModel.Router.Navigate.Execute(streamRecord); break; } case @"5": { ViewModel.Router.Navigate.Execute(userSettings); break; } case @"6": { ViewModel.Router.Navigate.Execute(ffmpegCommand); break; } } }).DisposeWith(d); NavigationView.SelectedItem = NavigationView.MenuItems.OfType <NavigationViewItem>().First(); this.Bind(ViewModel, vm => vm.Config.MainWindowsWidth, v => v.Width).DisposeWith(d); this.Bind(ViewModel, vm => vm.Config.MainWindowsHeight, v => v.Height).DisposeWith(d); MessageBus.Current.Listen <RoomStatus>() .Where(room => room.LiveStatus == LiveStatus.直播) .ObserveOnDispatcher() .Subscribe(room => NotifyIcon.ShowBalloonTip($@"{room.UserName} 开播了!", room.Title, BalloonIcon.Info)).DisposeWith(d); #region CloseReasonHack AddCloseReasonHook(); this.Events().Closing.Subscribe(e => { if (CloseReason == CloseReason.UserClosing) { Hide(); e.Cancel = true; } }).DisposeWith(d); #endregion });