Skip to content

Commit

Permalink
完成对TasksPage的改造
Browse files Browse the repository at this point in the history
  • Loading branch information
autodotua committed May 8, 2024
1 parent 5921751 commit f516a52
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 60 deletions.
58 changes: 3 additions & 55 deletions SimpleFFmpegGUI.WPF/Pages/TasksPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,20 @@
using FFMpegCore;
using FFMpegCore.Enums;
using FFMpegCore.Pipes;
using FzLib;
using FzLib.WPF;
using Mapster;
using Microsoft.Extensions.DependencyInjection;
using SimpleFFmpegGUI.Dto;
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;
Expand All @@ -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<object>().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<AllTasks>();
}

/// <summary>
/// Interaction logic for TasksPage.xaml
Expand All @@ -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<AllTasks>().RefreshAsync();
ViewModel = this.SetDataContext<TasksPageViewModel>();
}
}
}
16 changes: 11 additions & 5 deletions SimpleFFmpegGUI.WPF/Panels/TaskList.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<TaskListViewModel>();
}


public static readonly DependencyProperty ShowAllTasksProperty = DependencyProperty.Register(
nameof(ShowAllTasks), typeof(bool), typeof(TaskList));

public bool ShowAllTasks
{
get => (bool)GetValue(ShowAllTasksProperty);
Expand All @@ -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<MainWindow>().IsUiCompressMode && !ShowAllTasks ? 108 : double.NaN;
Expand Down
48 changes: 48 additions & 0 deletions SimpleFFmpegGUI.WPF/ViewModels/TasksPageViewModel.cs
Original file line number Diff line number Diff line change
@@ -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<object>().Count())
{
Pages = pages.ToList();
}
}

[ObservableProperty]
private IEnumerable pages;

public AllTasks AllTasks { get; }
}
}

0 comments on commit f516a52

Please sign in to comment.