Skip to content
This repository was archived by the owner on Feb 25, 2026. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 20 additions & 11 deletions Microsoft.Toolkit.Uwp.SampleApp/Pages/SampleController.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,8 @@ protected override async void OnNavigatedTo(NavigationEventArgs e)
{
try
{
var pageInstance = Activator.CreateInstance(CurrentSample.PageType);
SampleContent.Content = pageInstance;
SamplePage = Activator.CreateInstance(CurrentSample.PageType) as Page;
SampleContent.Content = SamplePage;

// Some samples use the OnNavigatedTo and OnNavigatedFrom
// Can't use Frame here because some samples depend on the current Frame
Expand All @@ -206,7 +206,7 @@ protected override async void OnNavigatedTo(NavigationEventArgs e)

if (method != null)
{
method.Invoke(pageInstance, new object[] { e });
method.Invoke(SamplePage, new object[] { e });
}
}
catch
Expand Down Expand Up @@ -348,6 +348,8 @@ protected override void OnNavigatedFrom(NavigationEventArgs e)

private void SamplePage_Loaded(object sender, RoutedEventArgs e)
{
SamplePage.Loaded -= SamplePage_Loaded;

if (CurrentSample != null && CurrentSample.HasXAMLCode)
{
_lastRenderedProperties = true;
Expand Down Expand Up @@ -516,17 +518,23 @@ private void UpdateXamlRender(string text)
if (CurrentSample.HasType)
{
root = SamplePage?.FindDescendantByName("XamlRoot");
}

if (root is Panel)
{
// If we've defined a 'XamlRoot' element to host us as a panel, use that.
(root as Panel).Children.Clear();
(root as Panel).Children.Add(element);
if (root is Panel)
{
// If we've defined a 'XamlRoot' element to host us as a panel, use that.
(root as Panel).Children.Clear();
(root as Panel).Children.Add(element);
}
else
{
// if we didn't find a XamlRoot host, then we replace the entire content of
// the provided sample page with the XAML.
SamplePage.Content = element;
}
}
else
{
// Otherwise, just replace the entire page's content
// Otherwise, just replace our entire presenter's content
SampleContent.Content = element;
}

Expand Down Expand Up @@ -675,7 +683,8 @@ public bool UseBackground
}
}

private Page SamplePage => SampleContent.Content as Page;
// The Loaded Instance of the backing .xaml.cs Page (if any)
private Page SamplePage { get; set; }

private bool CanChangePaneState => !_onlyDocumentation;

Expand Down