From f516a5274422025d39a31aa1f517b384f7efbd9b Mon Sep 17 00:00:00 2001 From: autodotua Date: Wed, 8 May 2024 15:40:10 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E5=AF=B9TasksPage=E7=9A=84?= =?UTF-8?q?=E6=94=B9=E9=80=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SimpleFFmpegGUI.WPF/Pages/TasksPage.xaml.cs | 58 +------------------ SimpleFFmpegGUI.WPF/Panels/TaskList.xaml.cs | 16 +++-- .../ViewModels/TasksPageViewModel.cs | 48 +++++++++++++++ 3 files changed, 62 insertions(+), 60 deletions(-) create mode 100644 SimpleFFmpegGUI.WPF/ViewModels/TasksPageViewModel.cs diff --git a/SimpleFFmpegGUI.WPF/Pages/TasksPage.xaml.cs b/SimpleFFmpegGUI.WPF/Pages/TasksPage.xaml.cs index f747e01..924bac7 100644 --- a/SimpleFFmpegGUI.WPF/Pages/TasksPage.xaml.cs +++ b/SimpleFFmpegGUI.WPF/Pages/TasksPage.xaml.cs @@ -2,7 +2,6 @@ using FFMpegCore; using FFMpegCore.Enums; using FFMpegCore.Pipes; -using FzLib; using FzLib.WPF; using Mapster; using Microsoft.Extensions.DependencyInjection; @@ -10,15 +9,13 @@ using SimpleFFmpegGUI.Manager; using SimpleFFmpegGUI.Model; using SimpleFFmpegGUI.WPF.Model; +using SimpleFFmpegGUI.WPF.ViewModels; using System; -using System.Collections; using System.Collections.Generic; -using System.ComponentModel; using System.Diagnostics; using System.Drawing; using System.Globalization; using System.IO; -using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; @@ -37,46 +34,6 @@ namespace SimpleFFmpegGUI.WPF.Pages { - public class TasksPageViewModel : INotifyPropertyChanged - { - public TasksPageViewModel() - { - AllTasks.PropertyChanged += AllTasks_PropertyChanged; - RefreshPages(); - } - - private void AllTasks_PropertyChanged(object sender, PropertyChangedEventArgs e) - { - RefreshPages(); - } - - private void RefreshPages() - { - var pages = Enumerable.Range(0, AllTasks.PageCount) - .Select(p => new - { - Label = "第" + (p + 1) + "页", - Value = p, - Value1 = p + 1 - }); - if (Pages == null || pages.Count() != Pages.Cast().Count()) - { - Pages = pages; - } - } - - private IEnumerable pages; - - public IEnumerable Pages - { - get => pages; - set => this.SetValueAndNotify(ref pages, value, nameof(Pages)); - } - - public event PropertyChangedEventHandler PropertyChanged; - - public AllTasks AllTasks => App.ServiceProvider.GetService(); - } /// /// Interaction logic for TasksPage.xaml @@ -85,19 +42,10 @@ public partial class TasksPage : UserControl { public TasksPageViewModel ViewModel { get; set; } - //private TimeSpan length; - //private double fps; - - public TasksPage(TasksPageViewModel viewModel) + public TasksPage() { InitializeComponent(); - ViewModel = viewModel; - DataContext = ViewModel; - } - - private async void FilterButton_Click(object sender, RoutedEventArgs e) - { - await App.ServiceProvider.GetService().RefreshAsync(); + ViewModel = this.SetDataContext(); } } } \ No newline at end of file diff --git a/SimpleFFmpegGUI.WPF/Panels/TaskList.xaml.cs b/SimpleFFmpegGUI.WPF/Panels/TaskList.xaml.cs index bec2ef2..00ee606 100644 --- a/SimpleFFmpegGUI.WPF/Panels/TaskList.xaml.cs +++ b/SimpleFFmpegGUI.WPF/Panels/TaskList.xaml.cs @@ -30,16 +30,14 @@ namespace SimpleFFmpegGUI.WPF.Panels { public partial class TaskList : UserControl { + public static readonly DependencyProperty ShowAllTasksProperty = DependencyProperty.Register( + nameof(ShowAllTasks), typeof(bool), typeof(TaskList)); + public TaskList() { InitializeComponent(); ViewModel = this.SetDataContext(); } - - - public static readonly DependencyProperty ShowAllTasksProperty = DependencyProperty.Register( - nameof(ShowAllTasks), typeof(bool), typeof(TaskList)); - public bool ShowAllTasks { get => (bool)GetValue(ShowAllTasksProperty); @@ -48,6 +46,14 @@ public bool ShowAllTasks public TaskListViewModel ViewModel { get; } + protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e) + { + base.OnPropertyChanged(e); + if (e.Property == ShowAllTasksProperty) + { + ViewModel.ShowAllTasks = (bool)e.NewValue; + } + } private void UpdateDetailHeight() { bdDetail.Height = App.ServiceProvider.GetService().IsUiCompressMode && !ShowAllTasks ? 108 : double.NaN; diff --git a/SimpleFFmpegGUI.WPF/ViewModels/TasksPageViewModel.cs b/SimpleFFmpegGUI.WPF/ViewModels/TasksPageViewModel.cs new file mode 100644 index 0000000..d4ff653 --- /dev/null +++ b/SimpleFFmpegGUI.WPF/ViewModels/TasksPageViewModel.cs @@ -0,0 +1,48 @@ +using CommunityToolkit.Mvvm.ComponentModel; +using CommunityToolkit.Mvvm.Input; +using FzLib; +using Microsoft.Extensions.DependencyInjection; +using SimpleFFmpegGUI.WPF.Model; +using System; +using System.Collections; +using System.ComponentModel; +using System.Linq; + +namespace SimpleFFmpegGUI.WPF.ViewModels +{ + public partial class TasksPageViewModel : ViewModelBase + { + public TasksPageViewModel(AllTasks allTasks) + { + AllTasks = allTasks; + AllTasks.PropertyChanged += AllTasks_PropertyChanged; + RefreshPages(); + } + + private void AllTasks_PropertyChanged(object sender, PropertyChangedEventArgs e) + { + RefreshPages(); + } + + [RelayCommand] + private void RefreshPages() + { + var pages = Enumerable.Range(0, AllTasks.PageCount) + .Select(p => new + { + Label = "第" + (p + 1) + "页", + Value = p, + Value1 = p + 1 + }); + if (Pages == null || pages.Count() != Pages.Cast().Count()) + { + Pages = pages.ToList(); + } + } + + [ObservableProperty] + private IEnumerable pages; + + public AllTasks AllTasks { get; } + } +} \ No newline at end of file