Skip to content

Instantly share code, notes, and snippets.

View wbokkers's full-sized avatar

Wim Bokkers wbokkers

  • The Netherlands
View GitHub Profile
@wbokkers
wbokkers / AppInstallerAndProgress.cs
Created November 9, 2022 11:53
How to use IAsyncOperationWithProgress
async Task InstallWithAppInstaller()
{
var pm = new PackageManager();
var volume = pm.GetDefaultPackageVolume();
var operationWithProgress = pm.AddPackageByAppInstallerFileAsync(new Uri("https://<the app installer location>"),
AddPackageByAppInstallerOptions.None, volume);
operationWithProgress.Progress = ReportProgress;
@wbokkers
wbokkers / Chunk.cs
Created August 17, 2022 13:51
Create chunks from array
public IEnumerable<ArraySegment<T>> Chunk<T>(T[] source, int chunkSize)
{
for (int i = 0; i < source.Length; i += chunkSize)
{
var remaining = source.Length - i;
var segmentSize = Math.Min(chunkSize, remaining);
yield return new ArraySegment<T>(source, i, segmentSize);
}
}
@wbokkers
wbokkers / App.xaml.cs
Last active November 23, 2022 20:57
Single Instancing Solution for WinUI 3
...
public partial class App : Application
{
private readonly SingleInstanceDesktopApp _singleInstanceApp;
public App()
{
InitializeComponent();
@wbokkers
wbokkers / TestControl.xaml
Created November 24, 2021 18:29
Immediate Crash on Loading ListView
<UserControl
x:Class="LayoutCycleTest.TestControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:layoutcycletest="using:LayoutCycleTest"
mc:Ignorable="d"
>
<UserControl.Resources>
@wbokkers
wbokkers / TestControl.xaml
Created November 4, 2021 12:50
Layout Cycle Detected Exception in Windows App SDK 1.0 Preview 3
<UserControl
x:Class="LayoutCycleTest.TestControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:layoutcycletest="using:LayoutCycleTest"
mc:Ignorable="d"
>
<UserControl.Resources>
@wbokkers
wbokkers / UWP-To-WinUI-Desktop-FileOpenPicker.cs
Last active October 26, 2021 07:37
UWP to WinUI Desktop - FileOpenPicker
FileOpenPicker open = new();
open.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
open.FileTypeFilter.Add("*");
WinUIConversionUtil.InitFileOpenPicker(open);
var file = await open.PickSingleFileAsync();
if (file != null)
{
@wbokkers
wbokkers / VolumeControl.cs
Last active May 11, 2022 03:02
Control the system volume from UWP, using the IAudioEndpointVolume interface
s/---
// Control the system volume from UWP, using the IAudioEndpointVolume interface
//
// Wim Bokkers
//
// Credits:
// * Reddit user sunius (https://www.reddit.com/user/sunius)
// See this thread: https://www.reddit.com/r/WPDev/comments/4kqzkb/launch_exe_with_parameter_in_uwp/d3jepi7/
// And this code: https://pastebin.com/cPhVCyWj
//