Skip to content

Instantly share code, notes, and snippets.

View andrewleader's full-sized avatar

Andrew Leader andrewleader

  • Microsoft
View GitHub Profile
@andrewleader
andrewleader / winui3singleinstance.md
Last active November 24, 2023 14:12
How to add single instancing to C# WinUI 3 app

Overall steps... Requires WinAppSDK 1.0.0 Preview 3 or greater and you must COMPILE FOR x64 (there's a known bug where this doesn't work from x86 apps)

  1. Add code to find existing instance, and if found, redirect and kill current process using System.Diagnostics.Process.GetCurrentProcess().Kill() (the WinUI 3 Exit() method doesn't work)
  2. Add code to handle the activation redirection
  3. Install the Microsoft.Windows.CsWin32 NuGet package
  4. Add the NativeMethods.txt file with two methods, ShowWindow and SetForegroundWindow (the WinUI 3 Activate and AppWindow Show methods don't work)
  5. In the redirection event, call ShowWindow and SetForegroundWindow

Full code sample: https://github.com/andrewleader/RedirectActivationWinUI3Sample

@andrewleader
andrewleader / NotificationsVisualizerLibrary.md
Last active December 6, 2021 22:13
Notifications Visualizer Library

Have you ever wanted to display a preview of your live tile in your app's settings page, so the user can instantly see how your various settings will affect their live tile?

Introducing the PreviewTile control! The PreviewTile is a XAML control that replicates the Start tiles, and fully supports displaying adaptive tile notifications. This is the same control that we use in the Notifications Visualizer.

Example of tile settings in a sample app

Using the PreviewTile control is simple. The API's to update properties and send notifications are very similar to the API's you already use for the actual live tiles.

How to use the PreviewTile

@andrewleader
andrewleader / WpfNet5Windows
Created December 10, 2020 16:46
Using new TFM's to target Windows
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net5.0-windows10.0.19041.0</TargetFramework>
<UseWPF>true</UseWPF>
</PropertyGroup>
</Project>
@andrewleader
andrewleader / host.json
Last active January 31, 2020 18:36
Disable dependencies/traces from Azure Functions Application Insights via host.json
{
"version": "2.0",
"logging": {
"applicationInsights": {
"samplingSettings": {
"isEnabled": true,
"initialSamplingPercentage": 0.0,
"minSamplingPercentage": 0.0,
"maxSamplingPercentage": 0.0,
"excludedTypes": "Event;Exception"
@andrewleader
andrewleader / Startup.cs
Created January 17, 2020 22:01
Disable Dependency tracking in Azure Functions
using Microsoft.ApplicationInsights.Channel;
using Microsoft.ApplicationInsights.DataContracts;
using Microsoft.ApplicationInsights.Extensibility;
using Microsoft.Azure.Functions.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection;
using System.Linq;
[assembly: FunctionsStartup(typeof(MyNamespace.Startup))]
namespace MyNamespace
@andrewleader
andrewleader / notification.js
Last active March 11, 2016 05:55 — forked from boyofgreen/notification.js
notification inside a Windows 10 app
if (typeof Windows !== 'undefined'&& typeof Windows.UI !== 'undefined' && typeof Windows.UI.Notifications !== 'undefined') {
// Construct the toast notification content
var toastContent = new Windows.Data.Xml.Dom.XmlDocument();
var toast = toastContent.createElement("toast");
toastContent.appendChild(toast);
var visual = toastContent.createElement("visual");
toast.appendChild(visual);
@andrewleader
andrewleader / livetile.js
Last active March 11, 2016 05:42 — forked from boyofgreen/livetile.js
code to push a live tile in Windows 10
if (typeof Windows !== 'undefined' &&
typeof Windows.UI !== 'undefined' &&
typeof Windows.UI.Notifications !== 'undefined') {
// Construct the tile notification content
var tileContent = new Windows.Data.Xml.Dom.XmlDocument();
var tile = tileContent.createElement("tile");
tileContent.appendChild(tile);