fix: fix palette demo initial data context issue.

(cherry picked from commit 30754a160db85fe6c1920729c5f33909c3566f79)
This commit is contained in:
rabbitism 2024-10-03 00:17:19 +08:00 committed by Zhang Dian
parent 62935eee6a
commit f7ef821538

View File

@ -13,17 +13,16 @@ public partial class PaletteDemo : UserControl
public PaletteDemo() public PaletteDemo()
{ {
InitializeComponent(); InitializeComponent();
this.DataContext = new PaletteDemoViewModel();
} }
protected override async void OnApplyTemplate(TemplateAppliedEventArgs e) protected override async void OnApplyTemplate(TemplateAppliedEventArgs e)
{ {
base.OnApplyTemplate(e); base.OnApplyTemplate(e);
PaletteDemoViewModel? vm = new PaletteDemoViewModel(); PaletteDemoViewModel? vm = this.DataContext as PaletteDemoViewModel;
await Dispatcher.UIThread.InvokeAsync(() => await Dispatcher.UIThread.InvokeAsync(() =>
{ {
vm.InitializeResources(); vm?.InitializeResources();
}); });
DataContext = vm;
} }
} }