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 / WrapPanelLineBreak.cs
Last active September 15, 2020 12:44
Line break in WrapPanel [WPF]
/// <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")
};
@SchreinerK
SchreinerK / SharedResourceDictionary.Simple.cs
Last active April 22, 2020 09:08
SharedResourceDictionary Simple
using System;
using System.Collections.Generic;
using System.Windows;
namespace KsWare.Gist {
// https://gist.github.com/SchreinerK/a753cee33a0e791dea6779bce730eade
public class SharedResourceDictionary : ResourceDictionary {
private static readonly Dictionary<Uri, WeakReference> SharedCache = new Dictionary<Uri, WeakReference>();
@SchreinerK
SchreinerK / SharedResourceDictionary.cs
Last active April 22, 2020 08:39
SharedResourceDictionary
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Windows;
// https://gist.github.com/SchreinerK/3a886e7f2294fcc2e2fceceaae0967c6
namespace KsWare.Gist {
/// <summary>
/// The shared resource dictionary is a specialized resource dictionary
@SchreinerK
SchreinerK / DoubleCompareConverter.cs
Created March 23, 2020 10:52
DoubleCompareConverter
using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;
namespace Converter
{
public class DoubleCompareConverter : IValueConverter
{
[SuppressMessage("ReSharper", "VirtualMemberNeverOverridden.Global", Justification = "Public API")]
[SuppressMessage("ReSharper", "UnusedMember.Global", Justification = "Public API")]
public class NotifyPropertyChangedBase : INotifyPropertyChanged {
/// <summary>
/// Sets a backing field value and if it's changed raise a notification.
/// </summary>
/// <typeparam name="T">The type of the value being set.</typeparam>
/// <param name="oldValue">A reference to the field to update.</param>
/// <param name="newValue">The new value.</param>
@SchreinerK
SchreinerK / DesignDataContext.xaml
Created October 1, 2019 08:51
Design DataContext
<d:DesignProperties.DataContext>
<$ViewModel$ />
</d:DesignProperties.DataContext>
d:DataContext="{d:DesignInstance Type=$ViewModel$, IsDesignTimeCreatable=False}"
@SchreinerK
SchreinerK / RegisterPackUriScheme.cs
Last active September 20, 2019 13:20
Problem with pack URIs in unit tests.
// http://jake.ginnivan.net/pack-uri-in-unit-tests/
PackUriHelper.Create(new Uri("reliable://0")); // register pack-uri
@SchreinerK
SchreinerK / MockServices.cs
Last active September 28, 2019 13:59
TestTools MockServices
// Source: https://gist.github.com/SchreinerK/73002d709fe6ee365cd3d7b43186300c#file-mockservices-cs
// Version: 1.6
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Runtime.Serialization;
// ReSharper disable LocalizableElement
// ReSharper disable CheckNamespace
@SchreinerK
SchreinerK / DependencyPropertyValueChangedEvent.cs
Created September 6, 2019 13:33
DependencyProperty ValueChanged event
var dpd = DependencyPropertyDescriptor.FromProperty(TextEditor.IsModifiedProperty, typeof(TextEditor));
dpd.AddValueChanged(_textEditor, TextEditor_IsModifiedChanged);
dpd.RemoveValueChanged(_textEditor, TextEditor_IsModifiedChanged);
@SchreinerK
SchreinerK / GenerateFullTypeName.cs
Created September 1, 2019 06:06
Generates the (C#) code for the specified type name.
public static string GenerateFullTypeName(Type type)
{
var retType = new StringBuilder();
if (type.IsGenericType)
{
var parentType = type.FullName.Split('`');
var arguments = type.GetGenericArguments();
var argList = new StringBuilder();