This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>>(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Forces a new line in a <see cref="WrapPanel"/> | |
/// </summary> | |
public class WrapPanelLineBreak : FrameworkElement { | |
public WrapPanelLineBreak() { | |
Height = 0; | |
var binding = new Binding { | |
RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor, typeof(WrapPanel), 1), | |
Path = new PropertyPath("ActualWidth") | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Globalization; | |
using System.Windows; | |
using System.Windows.Data; | |
namespace Converter | |
{ | |
public class DoubleCompareConverter : IValueConverter | |
{ |
NewerOlder