mirror of
https://github.com/Tyrrrz/DiscordChatExporter.git
synced 2026-05-02 02:28:54 +00:00
Automate view initialization
This commit is contained in:
@@ -30,8 +30,23 @@ public partial class ViewManager
|
||||
|
||||
view.DataContext ??= viewModel;
|
||||
|
||||
if (view.IsInitialized)
|
||||
{
|
||||
_ = viewModel.InitializeAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
view.Initialized += async (_, _) => await viewModel.InitializeAsync();
|
||||
}
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
public UserControl<T>? TryBindUserControl<T>(T viewModel)
|
||||
where T : ViewModelBase => TryBindView(viewModel) as UserControl<T>;
|
||||
|
||||
public Window<T>? TryBindWindow<T>(T viewModel)
|
||||
where T : ViewModelBase => TryBindView(viewModel) as Window<T>;
|
||||
}
|
||||
|
||||
public partial class ViewManager : IDataTemplate
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
|
||||
namespace DiscordChatExporter.Gui.Framework;
|
||||
@@ -9,6 +10,8 @@ public abstract class ViewModelBase : ObservableObject, IDisposable
|
||||
|
||||
protected void OnAllPropertiesChanged() => OnPropertyChanged(string.Empty);
|
||||
|
||||
public virtual Task InitializeAsync() => Task.CompletedTask;
|
||||
|
||||
protected virtual void Dispose(bool disposing) { }
|
||||
|
||||
public void Dispose()
|
||||
|
||||
Reference in New Issue
Block a user