Skip to content

Commit baaf046

Browse files
Added close confirm dialog
1 parent cf1fcf7 commit baaf046

File tree

5 files changed

+60
-0
lines changed

5 files changed

+60
-0
lines changed

VBAudioRouter/App.xaml.vb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
Imports VBAudioRouter.Utils
22
Imports Windows.UI
3+
Imports Windows.UI.Core.Preview
34

45
NotInheritable Class App
56
Inherits Application
67

78
Protected Overrides Sub OnLaunched(e As Windows.ApplicationModel.Activation.LaunchActivatedEventArgs)
9+
#Region "TitleBar"
810
Dim titlebar = ApplicationView.GetForCurrentView().TitleBar
911
Dim themeColor = ColorTranslator.FromHex("#E87D0D")
1012
Dim darkThemeColor = ColorTranslator.FromHex("#232323")
@@ -16,7 +18,22 @@ NotInheritable Class App
1618
titlebar.InactiveForegroundColor = Colors.LightGray
1719
titlebar.InactiveBackgroundColor = darkThemeColor
1820
titlebar.ButtonInactiveBackgroundColor = darkThemeColor
21+
#End Region
1922

23+
#Region "Close confirm"
24+
AddHandler SystemNavigationManagerPreview.GetForCurrentView().CloseRequested, Async Sub(sender As Object, ev As SystemNavigationCloseRequestedPreviewEventArgs)
25+
Dim deferral As Deferral = ev.GetDeferral()
26+
Try
27+
Dim dialog As New CloseConfirmDialog()
28+
dialog.RequestedTheme = ElementTheme.Dark
29+
ev.Handled = (Await dialog.ShowAsync()) = ContentDialogResult.Secondary
30+
Finally
31+
deferral.Complete()
32+
End Try
33+
End Sub
34+
#End Region
35+
36+
#Region "Launching app"
2037
Dim rootFrame As Frame = TryCast(Window.Current.Content, Frame)
2138
If rootFrame Is Nothing Then
2239
rootFrame = New Frame()
@@ -36,6 +53,7 @@ NotInheritable Class App
3653

3754
Window.Current.Activate()
3855
End If
56+
#End Region
3957
End Sub
4058

4159
Private Sub OnNavigationFailed(sender As Object, e As NavigationFailedEventArgs)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<ContentDialog
2+
x:Class="VBAudioRouter.CloseConfirmDialog"
3+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5+
xmlns:local="using:VBAudioRouter"
6+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
7+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
8+
mc:Ignorable="d"
9+
Title="Closing"
10+
PrimaryButtonText="Yes"
11+
SecondaryButtonText="No"
12+
PrimaryButtonClick="ContentDialog_PrimaryButtonClick"
13+
SecondaryButtonClick="ContentDialog_SecondaryButtonClick">
14+
15+
<StackPanel>
16+
<TextBlock>
17+
Do you really want to close the application?!
18+
<LineBreak />Closing the application might end in a lose of data!
19+
</TextBlock>
20+
</StackPanel>
21+
</ContentDialog>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
' The Content Dialog item template is documented at https://go.microsoft.com/fwlink/?LinkId=234238
2+
3+
Public NotInheritable Class CloseConfirmDialog
4+
Inherits ContentDialog
5+
6+
Private Sub ContentDialog_PrimaryButtonClick(sender As ContentDialog, args As ContentDialogButtonClickEventArgs)
7+
8+
End Sub
9+
10+
Private Sub ContentDialog_SecondaryButtonClick(sender As ContentDialog, args As ContentDialogButtonClickEventArgs)
11+
12+
End Sub
13+
End Class

VBAudioRouter/Package.appxmanifest

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353

5454
<Capabilities>
5555
<rescap:Capability Name="extendedExecutionBackgroundAudio"/>
56+
<rescap:Capability Name="confirmAppClose"/>
5657
<uap3:Capability Name="backgroundMediaPlayback"/>
5758
<Capability Name="internetClient" />
5859
<DeviceCapability Name="microphone"/>

VBAudioRouter/VBAudioRouter.vbproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,9 @@
156156
<Compile Include="Controls\TextToSpeechInputNodeControl.xaml.vb">
157157
<DependentUpon>TextToSpeechInputNodeControl.xaml</DependentUpon>
158158
</Compile>
159+
<Compile Include="Dialogs\CloseConfirmDialog.xaml.vb">
160+
<DependentUpon>CloseConfirmDialog.xaml</DependentUpon>
161+
</Compile>
159162
<Compile Include="Dialogs\ErrorDialog.xaml.vb">
160163
<DependentUpon>ErrorDialog.xaml</DependentUpon>
161164
</Compile>
@@ -302,6 +305,10 @@
302305
<SubType>Designer</SubType>
303306
<Generator>MSBuild:Compile</Generator>
304307
</Page>
308+
<Page Include="Dialogs\CloseConfirmDialog.xaml">
309+
<SubType>Designer</SubType>
310+
<Generator>MSBuild:Compile</Generator>
311+
</Page>
305312
<Page Include="Dialogs\ErrorDialog.xaml">
306313
<SubType>Designer</SubType>
307314
<Generator>MSBuild:Compile</Generator>

0 commit comments

Comments
 (0)