feat: simplify VM initialization.
This commit is contained in:
@@ -7,22 +7,17 @@ namespace Ursa.Demo.Pages;
|
||||
|
||||
public partial class NotificationDemo : UserControl
|
||||
{
|
||||
private NotificationDemoViewModel _viewModel;
|
||||
|
||||
public NotificationDemo()
|
||||
{
|
||||
InitializeComponent();
|
||||
_viewModel = new NotificationDemoViewModel();
|
||||
DataContext = _viewModel;
|
||||
}
|
||||
|
||||
protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
|
||||
{
|
||||
base.OnAttachedToVisualTree(e);
|
||||
if (DataContext is not NotificationDemoViewModel vm) return;
|
||||
var topLevel = TopLevel.GetTopLevel(this);
|
||||
if (topLevel is null)
|
||||
return;
|
||||
_viewModel.NotificationManager = WindowNotificationManager.TryGetNotificationManager(topLevel, out var manager)
|
||||
vm.NotificationManager = WindowNotificationManager.TryGetNotificationManager(topLevel, out var manager)
|
||||
? manager
|
||||
: new WindowNotificationManager(topLevel);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user