Skip to content

Instantly share code, notes, and snippets.

@winkel
winkel / WatermarkAdorner.cs
Created February 15, 2014 17:31
WPF Watermark as adoner
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Media;
/// <summary>
/// Adorner for the watermark
/// </summary>
internal class WatermarkAdorner : Adorner
@winkel
winkel / AsyncHelpers.cs
Created January 9, 2014 13:02
AsyncHelpers wykonywanie metody asynchronicznej synchronicznie
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
//http://social.msdn.microsoft.com/Forums/en-US/163ef755-ff7b-4ea5-b226-bbe8ef5f4796/is-there-a-pattern-for-calling-an-async-method-synchronously?forum=async
namespace ACME
{
public static class AsyncHelpers
{
@winkel
winkel / LockHolder.cs
Created October 16, 2013 18:06
LockHolder
// http://www.informit.com/articles/article.aspx?p=1231461
public sealed class LockHolder<T> : IDisposable where T : class
{
private T handle;
private bool holdsLock;
public LockHolder(T handle, int milliSecondTimeout)
{
this.handle = handle;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using Windows.Foundation;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Media.Animation;
namespace SharpGIS.Metro.Controls
@winkel
winkel / uninstall.bat
Created July 9, 2013 08:29
How to uninstall all ClickOnce apps
rundll32 dfshim CleanOnlineAppCache
@winkel
winkel / gist:5946926
Created July 8, 2013 07:41
NTP: GetNetworkTime
public static DateTime GetNetworkTime()
{
//default Windows time server
const string ntpServer = "time.windows.com";
// NTP message size - 16 bytes of the digest (RFC 2030)
var ntpData = new byte[48];
//Setting the Leap Indicator, Version Number and Mode values
ntpData[0] = 0x1B; //LI = 0 (no warning), VN = 3 (IPv4 only), Mode = 3 (Client Mode)
git gc --prune=now --aggressive
@winkel
winkel / CommandMap.cs
Last active February 6, 2016 01:36
CommandMap
// THIS SOFTWARE COMES "AS IS", WITH NO WARRANTIES. THIS
// MEANS NO EXPRESS, IMPLIED OR STATUTORY WARRANTY, INCLUDING
// WITHOUT LIMITATION, WARRANTIES OF MERCHANTABILITY OR FITNESS
// FOR A PARTICULAR PURPOSE OR ANY WARRANTY OF TITLE OR
// NON-INFRINGEMENT.
//
// MICROSOFT WILL NOT BE LIABLE FOR ANY DAMAGES RELATED TO
// THE SOFTWARE, INCLUDING DIRECT, INDIRECT, SPECIAL,
// CONSEQUENTIAL OR INCIDENTAL DAMAGES, TO THE MAXIMUM EXTENT
// THE LAW PERMITS, NO MATTER WHAT LEGAL THEORY IT IS
@winkel
winkel / gist:5344489
Created April 9, 2013 09:48
FindVisualChild in WinRT
private T FindVisualChild<T>(DependencyObject obj)
where T : DependencyObject
{
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(obj); i++)
{
DependencyObject child = VisualTreeHelper.GetChild(obj, i);
if (child != null && child is T)
return (T) child;
else
@winkel
winkel / AttachedCommands.cs
Last active December 18, 2015 10:40
WinRT AttachedCommands
public static class AttachedCommands
{
public static readonly DependencyProperty ControlTappedCommandProperty =
DependencyProperty.RegisterAttached("ControlTappedCommand",
typeof(ICommand), typeof(AttachedCommands),
new PropertyMetadata(null, new PropertyChangedCallback(AttachOrRemoveUIElementTappedEvent)));
public static ICommand GetControlTappedCommand(DependencyObject obj)
{
return (ICommand)obj.GetValue(ControlTappedCommandProperty);