Skip to content

Instantly share code, notes, and snippets.

View SchreinerK's full-sized avatar

Kay-Uwe Schreiner (kux) SchreinerK

View GitHub Profile
@SchreinerK
SchreinerK / icons.rc
Last active September 30, 2024 06:36
Multiple Icons in exe
101 ICON "Resources/app.ico"
102 ICON "Resources/second.ico"
201 24 "app.manifest" <- optional
@SchreinerK
SchreinerK / CopyToOutputDirectory.csproj
Created August 25, 2024 14:46
Copy all 'Page' files with 'CopyToOutputDirectory=Always' setting
<Project Sdk="Microsoft.NET.Sdk">
...
<Target Name="CopyPagesToOutputDirectory" AfterTargets="Build">
<!-- Copy all 'Page' files with 'CopyToOutputDirectory' setting -->
<Copy SourceFiles="@(Page)" DestinationFolder="$(OutputPath)%(RelativeDir)"
Condition="'%(Page.CopyToOutputDirectory)' == 'Always'" />
</Target>
...
</Project
@SchreinerK
SchreinerK / AlternateContent.cs
Created August 19, 2024 09:29
mc:AlternateContent, mc:Choice
using System.Windows.Markup;
#if NET8_0
[assembly: XmlnsDefinition("http://schemas.custom.com/net8/xaml", "KsWare.Presentation.Themes.Core.Net8")]
#endif
namespace KsWare.Presentation.Themes.Core.Net8 {class Dummy{} }
@SchreinerK
SchreinerK / FastString.cs
Last active August 18, 2024 23:37
string.Create with stackalloc (.net core)
public override string ToString() =>
string.Create(null, stackalloc char[256], $"Type={GetType().Name}");
@SchreinerK
SchreinerK / Default.cs
Created April 18, 2023 15:45
Gets the default value for a Type.
public static class Utils {
public static object? Default(Type type) {
return Type.GetTypeCode(type) switch {
TypeCode.Boolean => false,
TypeCode.String => null,
TypeCode.Char => '\0',
TypeCode.SByte => (sbyte)0, TypeCode.Byte => (byte)0, TypeCode.Int16 => (short)0,
TypeCode.UInt16 => (ushort)0, TypeCode.Int32 => 0, TypeCode.UInt32 => (uint)0,
TypeCode.Int64 => (long)0, TypeCode.UInt64 => (ulong)0,
TypeCode.Single => 0.0f, TypeCode.Double => 0.0d, TypeCode.Decimal => 0m,
@SchreinerK
SchreinerK / PopupWindow.cs
Created December 2, 2022 10:09
Show Window on Mouse Position
public partial class PopupWindow : Window {
public PopupWindow() {
InitializeComponent();
WindowStartupLocation = WindowStartupLocation.Manual;
Loaded += (s, e) => { // HACK1: use Loaded
Mouse.Capture(this); // HACK2: use Capture
var p = PointToScreen(Mouse.GetPosition(this));
Mouse.Capture(null);
@SchreinerK
SchreinerK / CompareBinding.cs
Last active October 6, 2021 17:52
CompareBinding
// SOURCE: https://gist.github.com/SchreinerK/299093195aebf1d3ef0d413659255c0d
using System;
using System.Collections;
using System.Globalization;
using System.Windows;
using System.Windows.Data;
// ReSharper disable once CheckNamespace
namespace KsWare.Presentation {
@SchreinerK
SchreinerK / CommandBindingMapper.cs
Last active October 1, 2021 10:26
KsWare.Presentaion.Input.CommandBindingMapper
// GIST: https://gist.github.com/SchreinerK/0aa450669ba0f66dbf821f92b15c1a66
using System.Windows;
using System.Windows.Data;
using System.Windows.Input;
using KsWare.Presentation.ViewFramework;
// ReSharper disable once CheckNamespace
namespace KsWare.Presentation.Input {
@SchreinerK
SchreinerK / AsyncHelper.cs
Created September 29, 2021 08:27
KsWare.Threading.AsyncHelper
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
namespace KsWare.Threading {
public static class AsyncHelper {
public static Task<TResult> RunAsync<TResult>(Func<TResult> func) => Task.Run<TResult>(() => func());
@SchreinerK
SchreinerK / PropertyChangedDistributor.cs
Created November 26, 2020 14:33
PropertyChangedDistributor
using System;
using System.Collections.Generic;
using System.ComponentModel;
namespace Common {
public sealed class PropertyChangedDistributor: IDisposable {
private readonly INotifyPropertyChanged _obj;
private readonly Dictionary<string, List<Entry>> _subscriptions = new Dictionary<string, List<Entry>>();