I have a UWP app that has multiple AppWindows. I want to display a common contentdialog that is defined in XAML on the MainPage on this AppWindow. I tried setting the XamlRoot but get this error: System.Exception: 'Catastrophic failure Cannot change XamlRoot when it is already set'.
Here is my XAML Code:
<ContentDialog x:Name="DetailsDialog" x:FieldModifier="public" Title="Details" CloseButtonText="Close" Margin="10,50,-10,-50" Visibility="Collapsed">
<ScrollViewer x:Name="DetailsScrollViewer" x:FieldModifier="Public">
<StackPanel x:Name="DetailsPanel" x:FieldModifier="public">
<Frame x:Name="DetailsContentFrame" x:FieldModifier="public" Padding="0,0,0,0" IsTabStop="True">
</Frame>
</StackPanel>
</ScrollViewer>
</ContentDialog>
This is the AppWindow's Code Behind to show the ContentDialog on the AppWindow:
PrintableArea.Children.Remove(ProcedureNotesPanel);
mainPage.DetailsPanel.Children.Add(ProcedureNotesPanel);
ProcedureNotesPanel.Visibility = Visibility.Visible;
mainPage.DetailsDialog.Title = title;
mainPage.DetailsDialog.Visibility = Visibility.Visible;
mainPage.DetailsDialog.XamlRoot = null;
mainPage.DetailsDialog.XamlRoot = ((FrameworkElement)sender).XamlRoot;
await mainPage.DetailsDialog.ShowAsync();
ProcedureNotesPanel.Visibility = Visibility.Collapsed;
mainPage.DetailsPanel.Children.Remove(ProcedureNotesPanel);
PrintableArea.Children.Add(ProcedureNotesPanel);
What am I doing wrong? I tried setting the XamlRoot to null first but even that throws the same exception.
Thanks.
After some more research and trial and error, I was able to achieve the intended outcome by creating a new ContentDialog instead of using an existing one on MainPage.