Skip to content

Commit 5423eae

Browse files
committed
feat(IRouteNotifyer): Add code for listening for Routechanges
1 parent d0d8b27 commit 5423eae

File tree

4 files changed

+18
-10
lines changed

4 files changed

+18
-10
lines changed

src/DevTKSS.Uno.Samples.sln

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ Global
3737
{88A95F19-AAAB-6B45-A5D7-8BABCE37F25C}.Debug|Any CPU.Build.0 = Debug|Any CPU
3838
{88A95F19-AAAB-6B45-A5D7-8BABCE37F25C}.Release|Any CPU.ActiveCfg = Release|Any CPU
3939
{88A95F19-AAAB-6B45-A5D7-8BABCE37F25C}.Release|Any CPU.Build.0 = Release|Any CPU
40+
{88A95F19-AAAB-6B45-A5D7-8BABCE37F25C}.Release|x64.ActiveCfg = Release|Any CPU
41+
{88A95F19-AAAB-6B45-A5D7-8BABCE37F25C}.Release|x64.Build.0 = Release|Any CPU
42+
{88A95F19-AAAB-6B45-A5D7-8BABCE37F25C}.Release|x86.ActiveCfg = Release|Any CPU
43+
{88A95F19-AAAB-6B45-A5D7-8BABCE37F25C}.Release|x86.Build.0 = Release|Any CPU
4044
EndGlobalSection
4145
GlobalSection(SolutionProperties) = preSolution
4246
HideSolutionNode = FALSE

src/DevTKSS.Uno.XamlNavigationApp-1/Presentation/MainModel.cs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,27 @@
1-
using DevTKSS.Uno.XamlNavigationApp.Models;
2-
31
namespace DevTKSS.Uno.XamlNavigationApp.Presentation;
42

53
public partial record MainModel
64
{
7-
private INavigator _navigator;
5+
private readonly INavigator _navigator;
6+
private readonly IRouteNotifier _routeNotifier;
87

98
public MainModel(
109
IStringLocalizer localizer,
1110
IOptions<AppConfig> appInfo,
12-
INavigator navigator)
11+
INavigator navigator,
12+
IRouteNotifier routeNotifier)
1313
{
1414
_navigator = navigator;
15-
Title = "Main";
16-
Title += $" - {localizer["ApplicationName"]}";
17-
Title += $" - {appInfo?.Value?.Environment}";
15+
_routeNotifier = routeNotifier;
16+
_routeNotifier.RouteChanged += Main_OnRouteChanged;
17+
}
18+
19+
private async void Main_OnRouteChanged(object? sender, RouteChangedEventArgs e)
20+
{
21+
await Title.SetAsync(e.Navigator?.Route?.ToString());
1822
}
1923

20-
public string? Title { get; }
24+
public IState<string> Title => State<string>.Value(this, () => _navigator.Route?.ToString() ?? string.Empty);
2125

2226
public IState<string> Name => State<string>.Value(this, () => string.Empty);
2327

src/DevTKSS.Uno.XamlNavigationApp-1/Presentation/MainPage.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
NavigationCacheMode="Required"
99
Background="{ThemeResource BackgroundBrush}">
1010
<Page.Resources>
11-
<!--<Thickness x:Key="NavigationViewHeaderMargin">20,20,20,20</Thickness>-->
11+
<Thickness x:Key="NavigationViewHeaderMargin">20,20,20,20</Thickness>
1212
<!--Would expect this to be not needed when setting IsTitleBarAutoPaddingEnabled to false, but that does not do anything, so use this instead.
1313
https://learn.microsoft.com/de-de/windows/apps/design/controls/navigationview#top-whitespace-->
1414
</Page.Resources>

src/DevTKSS.Uno.XamlNavigationApp-1/app.manifest

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
3-
<assemblyIdentity version="1.0.0.0" name="UnoApp2.Windows.app"/>
3+
<assemblyIdentity version="1.0.0.0" name="DevTKSS.Uno.XamlNavigationApp.app"/>
44

55
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
66
<application>

0 commit comments

Comments
 (0)