-
Notifications
You must be signed in to change notification settings - Fork 15
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
The avalonie previewer in Visual Studio and Rider fails to load when the view derives from AvaloniaInside.Shell.Page.
The reason is, that in OnLoaded, the Chain is still null
protected override void OnLoaded(RoutedEventArgs e)
{
base.OnLoaded(e);
ApplyNavigationBar();
AttachedNavigationBar?.UpdateView(this);
this[!ApplyTopSafePaddingProperty] = this[!ShellView.EnableSafeAreaForTopProperty];
this[!ApplyBottomSafePaddingProperty] = this[!ShellView.EnableSafeAreaForBottomProperty];
this[!ApplyLeftSafePaddingProperty] = this[!ShellView.EnableSafeAreaForLeftProperty];
this[!ApplyRightSafePaddingProperty] = this[!ShellView.ApplyRightSafePaddingProperty];
IsModal = Chain.Type == NavigateType.Modal;
}to fix this, I propose adding the following check:
protected override void OnLoaded(RoutedEventArgs e)
{
base.OnLoaded(e);
ApplyNavigationBar();
AttachedNavigationBar?.UpdateView(this);
this[!ApplyTopSafePaddingProperty] = this[!ShellView.EnableSafeAreaForTopProperty];
this[!ApplyBottomSafePaddingProperty] = this[!ShellView.EnableSafeAreaForBottomProperty];
this[!ApplyLeftSafePaddingProperty] = this[!ShellView.EnableSafeAreaForLeftProperty];
this[!ApplyRightSafePaddingProperty] = this[!ShellView.ApplyRightSafePaddingProperty];
+ // allow previewer to display page-based views
+ if (Design.IsDesignMode && Chain is null)
+ return;
IsModal = Chain.Type == NavigateType.Modal;
}
in case the Chain should never be null at that point, I'd even propose
protected override void OnLoaded(RoutedEventArgs e)
{
base.OnLoaded(e);
ApplyNavigationBar();
AttachedNavigationBar?.UpdateView(this);
this[!ApplyTopSafePaddingProperty] = this[!ShellView.EnableSafeAreaForTopProperty];
this[!ApplyBottomSafePaddingProperty] = this[!ShellView.EnableSafeAreaForBottomProperty];
this[!ApplyLeftSafePaddingProperty] = this[!ShellView.EnableSafeAreaForLeftProperty];
this[!ApplyRightSafePaddingProperty] = this[!ShellView.ApplyRightSafePaddingProperty];
// allow previewer to display page-based views
if (Design.IsDesignMode && Chain is null)
return;
+ if (Chain is null)
+ throw new InvalidOperationException("Chain must not be null");
IsModal = Chain.Type == NavigateType.Modal;
}
That way, if there is a configuration error, the developer gets a much more descriptive error than just a NRE.
What do you think?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working