mirror of
https://gitcode.com/gh_mirrors/se/Semi.Avalonia
synced 2026-04-29 20:53:23 +08:00
feat: implement singleton pattern for PaletteDemoViewModel and add initialization check
This commit is contained in:
@@ -12,14 +12,16 @@ public partial class PaletteDemo : UserControl
|
||||
public PaletteDemo()
|
||||
{
|
||||
InitializeComponent();
|
||||
this.DataContext = new PaletteDemoViewModel();
|
||||
this.DataContext = PaletteDemoViewModel.Instance.Value;
|
||||
}
|
||||
|
||||
protected override async void OnApplyTemplate(TemplateAppliedEventArgs e)
|
||||
{
|
||||
base.OnApplyTemplate(e);
|
||||
PaletteDemoViewModel? vm = this.DataContext as PaletteDemoViewModel;
|
||||
await Dispatcher.UIThread.InvokeAsync(() => { vm?.InitializeResources(); });
|
||||
if (this.DataContext is PaletteDemoViewModel vm && !vm.IsInitialized)
|
||||
{
|
||||
await Dispatcher.UIThread.InvokeAsync(() => { vm?.InitializeResources(); });
|
||||
}
|
||||
}
|
||||
|
||||
public async Task Copy(object? o)
|
||||
@@ -31,4 +33,4 @@ public partial class PaletteDemo : UserControl
|
||||
await c.SetTextAsync(o.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user