Skip to content

Fixed stack corruption bug in InAppNotification in sample #3802

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
10 commits merged into from
Mar 4, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ namespace Microsoft.Toolkit.Uwp.SampleApp.SamplePages
{
public sealed partial class InAppNotificationPage : Page, IXamlRenderListener
{
private ControlTemplate _defaultInAppNotificationControlTemplate;
private ControlTemplate _customInAppNotificationControlTemplate;
private InAppNotification _exampleInAppNotification;
private InAppNotification _exampleCustomInAppNotification;
private InAppNotification _exampleVSCodeInAppNotification;
Expand All @@ -36,9 +34,7 @@ public void OnXamlRendered(FrameworkElement control)
NotificationDuration = 0;

_exampleInAppNotification = control.FindChild("ExampleInAppNotification") as InAppNotification;
_defaultInAppNotificationControlTemplate = _exampleInAppNotification?.Template;
_exampleCustomInAppNotification = control.FindChild("ExampleCustomInAppNotification") as InAppNotification;
_customInAppNotificationControlTemplate = _exampleCustomInAppNotification?.Template;
_exampleVSCodeInAppNotification = control.FindChild("ExampleVSCodeInAppNotification") as InAppNotification;
_resources = control.Resources;

Expand All @@ -53,24 +49,24 @@ private void Load()
{
SampleController.Current.RegisterNewCommand("Show notification with random text", (sender, args) =>
{
_exampleVSCodeInAppNotification?.Dismiss();
SetDefaultControlTemplate();
_exampleVSCodeInAppNotification.Dismiss(true);
_exampleCustomInAppNotification.Dismiss(true);
_exampleInAppNotification?.Show(GetRandomText(), NotificationDuration);
});

SampleController.Current.RegisterNewCommand("Show notification with object", (sender, args) =>
{
_exampleVSCodeInAppNotification?.Dismiss();
SetDefaultControlTemplate();
_exampleVSCodeInAppNotification.Dismiss(true);
_exampleCustomInAppNotification.Dismiss(true);

var random = new Random();
_exampleInAppNotification?.Show(new KeyValuePair<int, string>(random.Next(1, 10), GetRandomText()), NotificationDuration);
});

SampleController.Current.RegisterNewCommand("Show notification with buttons (without DataTemplate)", (sender, args) =>
{
_exampleVSCodeInAppNotification?.Dismiss();
SetDefaultControlTemplate();
_exampleVSCodeInAppNotification.Dismiss(true);
_exampleCustomInAppNotification.Dismiss(true);

var grid = new Grid()
{
Expand Down Expand Up @@ -126,46 +122,30 @@ private void Load()

SampleController.Current.RegisterNewCommand("Show notification with buttons (with DataTemplate)", (sender, args) =>
{
_exampleVSCodeInAppNotification?.Dismiss();
SetCustomControlTemplate(); // Use the custom template without the Dismiss button. The DataTemplate will handle re-adding it.
_exampleVSCodeInAppNotification.Dismiss(true);
_exampleInAppNotification.Dismiss(true);

object inAppNotificationWithButtonsTemplate = null;
bool? isTemplatePresent = _resources?.TryGetValue("InAppNotificationWithButtonsTemplate", out inAppNotificationWithButtonsTemplate);

if (isTemplatePresent == true && inAppNotificationWithButtonsTemplate is DataTemplate template)
object inAppNotificationWithButtonsTemplateResource = null;
bool? isTemplatePresent = _resources?.TryGetValue("InAppNotificationWithButtonsTemplate", out inAppNotificationWithButtonsTemplateResource);
if (isTemplatePresent == true && inAppNotificationWithButtonsTemplateResource is DataTemplate inAppNotificationWithButtonsTemplate)
{
_exampleInAppNotification.Show(template, NotificationDuration);
_exampleCustomInAppNotification.Show(inAppNotificationWithButtonsTemplate, NotificationDuration);
}
});

SampleController.Current.RegisterNewCommand("Show notification with Drop Shadow (based on default template)", (sender, args) =>
{
_exampleVSCodeInAppNotification.Dismiss();
SetDefaultControlTemplate();

// Update control template
object inAppNotificationDropShadowControlTemplate = null;
bool? isTemplatePresent = _resources?.TryGetValue("InAppNotificationDropShadowControlTemplate", out inAppNotificationDropShadowControlTemplate);

if (isTemplatePresent == true && inAppNotificationDropShadowControlTemplate is ControlTemplate template)
{
_exampleInAppNotification.Template = template;
}

_exampleInAppNotification.Show(GetRandomText(), NotificationDuration);
});

SampleController.Current.RegisterNewCommand("Show notification with Visual Studio Code template (info notification)", (sender, args) =>
{
_exampleInAppNotification.Dismiss();
_exampleInAppNotification.Dismiss(true);
_exampleCustomInAppNotification.Dismiss(true);
_exampleVSCodeInAppNotification.Show(NotificationDuration);
});

SampleController.Current.RegisterNewCommand("Dismiss", (sender, args) =>
{
// Dismiss all notifications (should not be replicated in production)
_exampleInAppNotification.Dismiss();
_exampleVSCodeInAppNotification.Dismiss();
_exampleInAppNotification.Dismiss(true);
_exampleCustomInAppNotification.Dismiss(true);
_exampleVSCodeInAppNotification.Dismiss(true);
});
}

Expand All @@ -182,18 +162,6 @@ private string GetRandomText()
}
}

private void SetDefaultControlTemplate()
{
// Update control template
_exampleInAppNotification.Template = _defaultInAppNotificationControlTemplate;
}

private void SetCustomControlTemplate()
{
// Update control template
_exampleInAppNotification.Template = _customInAppNotificationControlTemplate;
}

private void NotificationDurationTextBox_TextChanged(object sender, TextChangedEventArgs e)
{
int newDuration;
Expand Down
Loading