Skip to content
Merged
Show file tree
Hide file tree
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
36 changes: 21 additions & 15 deletions WinUIGallery/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,13 @@ protected override void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs ar

EnsureWindow();

MainWindow.Closed += (s, e) =>
if (NativeMethods.IsAppPackaged)
{
BadgeNotificationManager.Current.ClearBadge();
};
MainWindow.Closed += (s, e) =>
{
BadgeNotificationManager.Current.ClearBadge();
};
}
}

private void DebugSettings_BindingFailed(object sender, BindingFailedEventArgs e)
Expand Down Expand Up @@ -131,17 +134,20 @@ private async void EnsureWindow()
/// <param name="e">Details about the exception.</param>
private void HandleExceptions(object sender, Microsoft.UI.Xaml.UnhandledExceptionEventArgs e)
{
e.Handled = true; //Don't crash the app.

//Create the notification.
var notification = new AppNotificationBuilder()
.AddText("An exception was thrown.")
.AddText($"Type: {e.Exception.GetType()}")
.AddText($"Message: {e.Message}\r\n" +
$"HResult: {e.Exception.HResult}")
.BuildNotification();

//Show the notification
AppNotificationManager.Default.Show(notification);
if (NativeMethods.IsAppPackaged)
{
e.Handled = true; //Don't crash the app.

//Create the notification.
var notification = new AppNotificationBuilder()
.AddText("An exception was thrown.")
.AddText($"Type: {e.Exception.GetType()}")
.AddText($"Message: {e.Message}\r\n" +
$"HResult: {e.Exception.HResult}")
.BuildNotification();

//Show the notification
AppNotificationManager.Default.Show(notification);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
mc:Ignorable="d">

<StackPanel>
<InfoBar Margin="0,10,0,0" IsOpen="True" IsClosable="False" Severity="Warning" Title="BadgeNotificationManager is not available in unpackaged mode." Message="This API requires the app to be running in packaged mode (MSIX)."/>
<controls:ControlExample HeaderText="Setting badge notifications with count">
<StackPanel Spacing="8">
<Button Content="Set badge as count"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Microsoft.Windows.BadgeNotifications;
using System;
using System.Collections.Generic;
using WinUIGallery.Helpers;

namespace WinUIGallery.ControlPages;

Expand All @@ -22,34 +23,49 @@ public BadgeNotificationManagerPage()

private void SetBadgeCountButton_Click(object sender, RoutedEventArgs e)
{
BadgeNotificationManager.Current.SetBadgeAsCount((uint)BadgeCountBox.Value);
isBadgeSetted = true;
if (NativeMethods.IsAppPackaged)
{
BadgeNotificationManager.Current.SetBadgeAsCount((uint)BadgeCountBox.Value);
isBadgeSetted = true;
}
}

private void ClearBadgeButton_Click(object sender, RoutedEventArgs e)
{
BadgeNotificationManager.Current.ClearBadge();
if (NativeMethods.IsAppPackaged)
{
BadgeNotificationManager.Current.ClearBadge();
}
}

private void SetBadgeGlyphButton_Click(object sender, RoutedEventArgs e)
{
BadgeNotificationManager.Current.SetBadgeAsGlyph(selectedGlyph);
isBadgeSetted = true;
if (NativeMethods.IsAppPackaged)
{
BadgeNotificationManager.Current.SetBadgeAsGlyph(selectedGlyph);
isBadgeSetted = true;
}
}

private void BadgeCountBox_ValueChanged(NumberBox sender, NumberBoxValueChangedEventArgs args)
{
if (isBadgeSetted)
if (NativeMethods.IsAppPackaged)
{
BadgeNotificationManager.Current.SetBadgeAsCount((uint)BadgeCountBox.Value);
if (isBadgeSetted)
{
BadgeNotificationManager.Current.SetBadgeAsCount((uint)BadgeCountBox.Value);
}
}
}

private void BadgeNotificationGlyphsCombo_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (isBadgeSetted)
if (NativeMethods.IsAppPackaged)
{
BadgeNotificationManager.Current.SetBadgeAsGlyph(selectedGlyph);
if (isBadgeSetted)
{
BadgeNotificationManager.Current.SetBadgeAsGlyph(selectedGlyph);
}
}
}
}
15 changes: 12 additions & 3 deletions WinUIGallery/Samples/ControlPages/ScrollViewPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.IO;
using System.Numerics;
using Windows.Globalization.NumberFormatting;
using WinUIGallery.Helpers;

namespace WinUIGallery.ControlPages;

Expand Down Expand Up @@ -302,9 +303,17 @@ private string GetExample3CodeContent(string sampleCodeFileName)
{
if (!_example3CodeCache.TryGetValue(sampleCodeFileName, out var content))
{
var folder = Windows.ApplicationModel.Package.Current.InstalledLocation;
content = File.ReadAllText($"{folder.Path}\\Samples\\SampleCode\\ScrollView\\{sampleCodeFileName}.txt");
_example3CodeCache[sampleCodeFileName] = content; // Cache the content
string folderPath = AppContext.BaseDirectory;
if (NativeMethods.IsAppPackaged)
{
folderPath = Windows.ApplicationModel.Package.Current.InstalledLocation.Path;
}
string filePath = Path.Combine(folderPath, "Samples", "SampleCode", "ScrollView", $"{sampleCodeFileName}.txt");
if (File.Exists(filePath))
{
content = File.ReadAllText(filePath);
_example3CodeCache[sampleCodeFileName] = content; // Cache the content
}
}
return content;
}
Expand Down