Browse Source

Add TemplatedControlBase

pull/165/head
Ionite 1 year ago
parent
commit
8613ec1359
No known key found for this signature in database
  1. 5
      StabilityMatrix.Avalonia/Controls/DropTargetTemplatedControlBase.cs
  2. 24
      StabilityMatrix.Avalonia/Controls/ImageFolderCard.axaml.cs
  3. 40
      StabilityMatrix.Avalonia/Controls/TemplatedControlBase.cs
  4. 6
      StabilityMatrix.Avalonia/ViewModels/Inference/ImageFolderCardViewModel.cs

5
StabilityMatrix.Avalonia/Controls/DropTargetTemplatedControlBase.cs

@ -1,10 +1,9 @@
using Avalonia.Controls.Primitives;
using Avalonia.Input;
using Avalonia.Input;
using StabilityMatrix.Avalonia.ViewModels;
namespace StabilityMatrix.Avalonia.Controls;
public abstract class DropTargetTemplatedControlBase : TemplatedControl
public abstract class DropTargetTemplatedControlBase : TemplatedControlBase
{
protected DropTargetTemplatedControlBase()
{

24
StabilityMatrix.Avalonia/Controls/ImageFolderCard.axaml.cs

@ -1,31 +1,9 @@
using AsyncAwaitBestPractices;
using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.Threading;
using StabilityMatrix.Avalonia.ViewModels.Base;
using Avalonia.Input;
namespace StabilityMatrix.Avalonia.Controls;
public class ImageFolderCard : DropTargetTemplatedControlBase
{
/// <inheritdoc />
protected override void OnLoaded(RoutedEventArgs e)
{
base.OnLoaded(e);
if (DataContext is ViewModelBase vm)
{
vm.OnLoaded();
Dispatcher.UIThread
.InvokeAsync(async () =>
{
await vm.OnLoadedAsync();
})
.SafeFireAndForget();
}
}
/// <inheritdoc />
protected override void DropHandler(object? sender, DragEventArgs e)
{

40
StabilityMatrix.Avalonia/Controls/TemplatedControlBase.cs

@ -0,0 +1,40 @@
using AsyncAwaitBestPractices;
using Avalonia.Controls.Primitives;
using Avalonia.Interactivity;
using Avalonia.Threading;
using StabilityMatrix.Avalonia.ViewModels.Base;
namespace StabilityMatrix.Avalonia.Controls;
public abstract class TemplatedControlBase : TemplatedControl
{
/// <inheritdoc />
protected override void OnLoaded(RoutedEventArgs e)
{
base.OnLoaded(e);
if (DataContext is not ViewModelBase viewModel)
return;
// Run synchronous load then async load
viewModel.OnLoaded();
// Can't block here so we'll run as async on UI thread
Dispatcher.UIThread.InvokeAsync(viewModel.OnLoadedAsync).SafeFireAndForget();
}
/// <inheritdoc />
protected override void OnUnloaded(RoutedEventArgs e)
{
base.OnUnloaded(e);
if (DataContext is not ViewModelBase viewModel)
return;
// Run synchronous load then async load
viewModel.OnUnloaded();
// Can't block here so we'll run as async on UI thread
Dispatcher.UIThread.InvokeAsync(viewModel.OnUnloadedAsync).SafeFireAndForget();
}
}

6
StabilityMatrix.Avalonia/ViewModels/Inference/ImageFolderCardViewModel.cs

@ -6,9 +6,6 @@ using AsyncAwaitBestPractices;
using AsyncImageLoader;
using Avalonia;
using Avalonia.Controls.Notifications;
using Avalonia.Controls.Primitives;
using Avalonia.Input;
using Avalonia.Layout;
using Avalonia.Platform.Storage;
using Avalonia.Threading;
using CommunityToolkit.Mvvm.ComponentModel;
@ -17,7 +14,6 @@ using DynamicData;
using DynamicData.Binding;
using FuzzySharp;
using FuzzySharp.PreProcess;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using SkiaSharp;
using StabilityMatrix.Avalonia.Controls;
@ -27,8 +23,6 @@ using StabilityMatrix.Avalonia.Models;
using StabilityMatrix.Avalonia.Services;
using StabilityMatrix.Avalonia.ViewModels.Base;
using StabilityMatrix.Avalonia.ViewModels.Dialogs;
using StabilityMatrix.Avalonia.Views;
using StabilityMatrix.Avalonia.Views.Dialogs;
using StabilityMatrix.Core.Attributes;
using StabilityMatrix.Core.Models.Database;
using StabilityMatrix.Core.Models.FileInterfaces;

Loading…
Cancel
Save