@@ -195,8 +195,8 @@ protected override async void OnNavigatedTo(NavigationEventArgs e)
195
195
{
196
196
try
197
197
{
198
- var pageInstance = Activator . CreateInstance ( CurrentSample . PageType ) ;
199
- SampleContent . Content = pageInstance ;
198
+ SamplePage = Activator . CreateInstance ( CurrentSample . PageType ) as Page ;
199
+ SampleContent . Content = SamplePage ;
200
200
201
201
// Some samples use the OnNavigatedTo and OnNavigatedFrom
202
202
// Can't use Frame here because some samples depend on the current Frame
@@ -206,7 +206,7 @@ protected override async void OnNavigatedTo(NavigationEventArgs e)
206
206
207
207
if ( method != null )
208
208
{
209
- method . Invoke ( pageInstance , new object [ ] { e } ) ;
209
+ method . Invoke ( SamplePage , new object [ ] { e } ) ;
210
210
}
211
211
}
212
212
catch
@@ -348,6 +348,8 @@ protected override void OnNavigatedFrom(NavigationEventArgs e)
348
348
349
349
private void SamplePage_Loaded ( object sender , RoutedEventArgs e )
350
350
{
351
+ SamplePage . Loaded -= SamplePage_Loaded ;
352
+
351
353
if ( CurrentSample != null && CurrentSample . HasXAMLCode )
352
354
{
353
355
_lastRenderedProperties = true ;
@@ -516,17 +518,23 @@ private void UpdateXamlRender(string text)
516
518
if ( CurrentSample . HasType )
517
519
{
518
520
root = SamplePage ? . FindDescendantByName ( "XamlRoot" ) ;
519
- }
520
521
521
- if ( root is Panel )
522
- {
523
- // If we've defined a 'XamlRoot' element to host us as a panel, use that.
524
- ( root as Panel ) . Children . Clear ( ) ;
525
- ( root as Panel ) . Children . Add ( element ) ;
522
+ if ( root is Panel )
523
+ {
524
+ // If we've defined a 'XamlRoot' element to host us as a panel, use that.
525
+ ( root as Panel ) . Children . Clear ( ) ;
526
+ ( root as Panel ) . Children . Add ( element ) ;
527
+ }
528
+ else
529
+ {
530
+ // if we didn't find a XamlRoot host, then we replace the entire content of
531
+ // the provided sample page with the XAML.
532
+ SamplePage . Content = element ;
533
+ }
526
534
}
527
535
else
528
536
{
529
- // Otherwise, just replace the entire page 's content
537
+ // Otherwise, just replace our entire presenter 's content
530
538
SampleContent . Content = element ;
531
539
}
532
540
@@ -675,7 +683,8 @@ public bool UseBackground
675
683
}
676
684
}
677
685
678
- private Page SamplePage => SampleContent . Content as Page ;
686
+ // The Loaded Instance of the backing .xaml.cs Page (if any)
687
+ private Page SamplePage { get ; set ; }
679
688
680
689
private bool CanChangePaneState => ! _onlyDocumentation ;
681
690
0 commit comments