Skip to content

Commit eb599fb

Browse files
committed
Reduce code for back button
1 parent 87274a0 commit eb599fb

2 files changed

Lines changed: 5 additions & 15 deletions

File tree

AuraClick/MainWindow.xaml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
<TitleBar
2323
x:Name="AppTitleBar"
2424
x:Uid="AppTitleBar"
25-
BackRequested="AppTitleBar_BackRequested">
25+
BackRequested="TitleBar_BackRequested"
26+
IsBackButtonVisible="{x:Bind RootFrame.CanGoBack, Mode=OneWay}">
2627
<TitleBar.IconSource>
2728
<ImageIconSource ImageSource="Assets/AppIcon.ico" />
2829
</TitleBar.IconSource>
@@ -33,9 +34,6 @@
3334
MainPage.xaml rather than here so you can use Page features such as
3435
navigation events and the Loaded lifecycle.
3536
-->
36-
<Frame
37-
x:Name="RootFrame"
38-
Grid.Row="1"
39-
Navigated="RootFrame_Navigated" />
37+
<Frame x:Name="RootFrame" Grid.Row="1" />
4038
</Grid>
4139
</windowex:WindowEx>

AuraClick/MainWindow.xaml.cs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,8 @@ public MainWindow()
4545
RootFrame.Navigate(typeof(MainPage));
4646
}
4747

48-
private void AppTitleBar_BackRequested(TitleBar sender, object args)
48+
private void TitleBar_BackRequested(TitleBar sender, object args)
4949
{
50-
if (RootFrame.CanGoBack)
51-
{
52-
RootFrame.GoBack();
53-
}
54-
}
55-
56-
private void RootFrame_Navigated(object sender, NavigationEventArgs e)
57-
{
58-
AppTitleBar.IsBackButtonVisible = e.SourcePageType != typeof(MainPage);
50+
RootFrame.GoBack();
5951
}
6052
}

0 commit comments

Comments
 (0)