Ejemplo n.º 1
0
        public StreamRecordView(StreamRecordViewModel viewModel)
        {
            InitializeComponent();
            ViewModel = viewModel;

            this.WhenActivated(d =>
            {
                this.OneWayBind(ViewModel, vm => vm.RoomList, v => v.RoomListDataGrid.ItemsSource).DisposeWith(d);
                this.BindCommand(ViewModel, vm => vm.AddRoomCommand, v => v.AddMenuItem).DisposeWith(d);
                var selectedItem  = this.WhenAnyValue(v => v.RoomListDataGrid.SelectedItem);
                var selectedItems = this.WhenAnyValue(v => v.RoomListDataGrid.SelectedItems);
                this.BindCommand(ViewModel,
                                 vm => vm.ModifyRoomCommand,
                                 v => v.ModifyMenuItem,
                                 selectedItem).DisposeWith(d);
                this.BindCommand(ViewModel,
                                 vm => vm.RemoveRoomCommand,
                                 v => v.RemoveMenuItem,
                                 selectedItems).DisposeWith(d);
                this.BindCommand(ViewModel,
                                 vm => vm.RefreshRoomCommand,
                                 v => v.RefreshMenuItem,
                                 selectedItems).DisposeWith(d);
                this.BindCommand(ViewModel,
                                 vm => vm.OpenDirCommand,
                                 v => v.OpenDirMenuItem,
                                 selectedItem).DisposeWith(d);
                this.BindCommand(ViewModel,
                                 vm => vm.OpenUrlCommand,
                                 v => v.OpenUrlMenuItem,
                                 selectedItems).DisposeWith(d);
            });
        }
Ejemplo n.º 2
0
        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
            });