mlaumcherb/Млаумчерб.Клиент/видимое/DownloadItemView.axaml.cs
2024-09-29 08:21:48 +05:00

43 lines
1.1 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Avalonia.Controls;
using Avalonia.Interactivity;
using Avalonia.Threading;
using Млаумчерб.Клиент.сеть;
namespace Млаумчерб.Клиент.видимое;
public partial class DownloadTaskView : UserControl
{
private readonly NetworkTask _task;
private readonly Action<DownloadTaskView> _removeFromList;
public DownloadTaskView()
{
throw new NotImplementedException();
}
public DownloadTaskView(NetworkTask task, Action<DownloadTaskView> removeFromList)
{
_task = task;
_removeFromList = removeFromList;
InitializeComponent();
NameText.Text = task.Name;
task.OnProgress += ReportProgress;
}
void ReportProgress(DownloadProgress progress)
{
Dispatcher.UIThread.Invoke(() =>
{
DownloadedProgressText.Text = progress.ToString();
});
}
private void RemoveFromList(object? sender, RoutedEventArgs e)
{
_task.Cancel();
Dispatcher.UIThread.Invoke(() => _removeFromList.Invoke(this));
}
}