fix/inactive-toolbar-buttons #38
3 changed files with 23 additions and 5 deletions
PostIt: show ViewLocator fallback errors in navigation
commit
600bb81be1
|
|
@ -324,10 +324,12 @@ public partial class App : Application
|
|||
$"Template for {vm.GetType().Name} returned <null>.");
|
||||
}
|
||||
|
||||
if (view is not Page page)
|
||||
var page = view as Page;
|
||||
if (page is null)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
$"Template for {vm.GetType().Name} returned {view.GetType().Name}, expected a Page.");
|
||||
// NavigationPage expects Page instances. Wrap any fallback control
|
||||
// (e.g. ViewLocator error TextBlock) into a ContentPage so it can render.
|
||||
page = new ContentPage { Content = view };
|
||||
}
|
||||
|
||||
page.DataContext = vm;
|
||||
|
|
|
|||
|
|
@ -21,6 +21,18 @@ public class ViewLocator : IDataTemplate
|
|||
}
|
||||
|
||||
public Control Build(object? data)
|
||||
{
|
||||
try
|
||||
{
|
||||
return BuildCore(data);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return new TextBlock { Text = $"ViewLocator threw: {ex}" };
|
||||
}
|
||||
}
|
||||
|
||||
private Control BuildCore(object? data)
|
||||
{
|
||||
return data switch
|
||||
{
|
||||
|
|
|
|||
|
|
@ -437,7 +437,11 @@ public partial class MainPageViewModel : ViewModelBase
|
|||
[RelayCommand(CanExecute = nameof(CanManageAcl))]
|
||||
public async Task ManageAcl()
|
||||
{
|
||||
if (SelectedPost is null) return;
|
||||
if (SelectedPost is null)
|
||||
{
|
||||
StatusMessage = "Select an existing post before managing ACL.";
|
||||
return;
|
||||
}
|
||||
await ((App)App.Current!).PushPageAsync(GetACLViewModel(SelectedPost)).ConfigureAwait(true);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue