-
Notifications
You must be signed in to change notification settings - Fork 725
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Adding handlers for frame and page
- Loading branch information
1 parent
661b53b
commit 25fe06f
Showing
3 changed files
with
78 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using System; | ||
using System.Reflection.Metadata; | ||
using Uno.UI.Helpers; | ||
|
||
[assembly: ElementMetadataUpdateHandlerAttribute(typeof(Windows.UI.Xaml.Controls.Frame), typeof(Windows.UI.Xaml.Controls.FrameElementMetadataUpdateHandler))] | ||
|
||
namespace Windows.UI.Xaml.Controls | ||
{ | ||
public partial class FrameElementMetadataUpdateHandler | ||
{ | ||
public static void ElementUpdate(FrameworkElement element, Type[] updatedTypes) | ||
{ | ||
var frame = element as Frame; | ||
if (frame is null) | ||
{ | ||
return; | ||
} | ||
|
||
foreach (var entry in frame.BackStack) | ||
{ | ||
var expectedType = entry.SourcePageType.GetReplacementType(); | ||
if (entry.Instance is not null && | ||
entry.Instance.GetType() != expectedType) | ||
{ | ||
var dc = entry.Instance.DataContext; | ||
entry.Instance = Activator.CreateInstance(expectedType) as Page; | ||
entry.Instance.Frame = frame; | ||
if (entry.Instance is not null) | ||
{ | ||
entry.Instance.DataContext = dc; | ||
} | ||
} | ||
|
||
if (entry.SourcePageType is not null && | ||
entry.SourcePageType != expectedType) | ||
{ | ||
entry.SourcePageType = expectedType; | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using System; | ||
using System.Reflection.Metadata; | ||
using Uno.UI.Helpers; | ||
|
||
[assembly: ElementMetadataUpdateHandlerAttribute(typeof(Windows.UI.Xaml.Controls.Page), typeof(Windows.UI.Xaml.Controls.PageElementMetadataUpdateHandler))] | ||
|
||
namespace Windows.UI.Xaml.Controls | ||
{ | ||
public partial class PageElementMetadataUpdateHandler | ||
{ | ||
public static void AfterElementReplaced(FrameworkElement oldView, FrameworkElement newView, Type[] updatedTypes) | ||
{ | ||
if (oldView is Page oldPage && | ||
newView is Page newPage) | ||
{ | ||
newPage.Frame = oldPage.Frame; | ||
|
||
// If we've replaced the Page in its frame, we may need to | ||
// swap the content property as well. If may be required | ||
// if the frame is handled by a (native) FramePresenter. | ||
newPage.Frame.Content = newPage; | ||
} | ||
} | ||
} | ||
} |