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 TaskHelper | |
{ | |
public static async Task<IEnumerable<TResult>> EnumerateTaskResults<TResult>(IEnumerable<Func<TResult>> source, TimeSpan timeout, CancellationToken cancellationToken) | |
{ | |
var enumerateTasks = source | |
.Select(x => Task.Run(() => x.Invoke())) | |
.ToArray(); | |
var timeoutTask = Task.Delay(timeout, cancellationToken); |
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.Windows; | |
public class TupleTest | |
{ | |
public void TupleClipboardTest1() | |
{ | |
(int, string) original = (11, "Eleven"); | |
Clipboard.SetData(DataFormats.Serializable, original); | |
object retrieved = Clipboard.GetData(DataFormats.Serializable); |
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 WindowHelper | |
{ | |
public static bool GetIsDragEnabled(DependencyObject obj) | |
{ | |
return (bool)obj.GetValue(IsDragEnabledProperty); | |
} | |
public static void SetIsDragEnabled(DependencyObject obj, bool value) | |
{ | |
obj.SetValue(IsDragEnabledProperty, value); | |
} |
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 WindowHelper | |
{ | |
public static byte[] GetImageData(FrameworkElement element) | |
{ | |
var dpi = VisualTreeHelper.GetDpi(element); | |
var rtb = new RenderTargetBitmap( | |
(int)(element.ActualWidth * dpi.DpiScaleX), | |
(int)(element.ActualHeight * dpi.DpiScaleY), | |
dpi.PixelsPerInchX, |
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
Add-Type @" | |
using System; | |
using System.Runtime.InteropServices; | |
public static class MonitorHelper | |
{ | |
[DllImport("User32.dll")] | |
public static extern IntPtr MonitorFromWindow( | |
IntPtr hwnd, | |
int dwFlags); |
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 async Task<string[]> ExecuteCommandAsync(string command) | |
{ | |
using var p = new Process(); | |
p.StartInfo = new ProcessStartInfo("cmd.exe") | |
{ | |
CreateNoWindow = true, | |
UseShellExecute = false, | |
RedirectStandardInput = true, | |
RedirectStandardOutput = true | |
}; |
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
<TextBlock> | |
<TextBlock.Text> | |
<!-- View is bound to View Model which has Version Version property. --> | |
<MultiBinding StringFormat="v{0}.{1}"> | |
<Binding Path="Version.Major"/> | |
<Binding Path="Version.Minor"/> | |
</MultiBinding> | |
</TextBlock.Text> | |
</TextBlock> |
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
[MarkupExtensionReturnType(typeof(object[]))] | |
public class ArrayConstructorExtension : MarkupExtension | |
{ | |
private readonly object[] _elements; | |
public ArrayConstructorExtension(object a) => _elements = new[] { a }; | |
public ArrayConstructorExtension(object a, object b) => _elements = new[] { a, b }; | |
public ArrayConstructorExtension(object a, object b, object c) => _elements = new[] { a, b, c }; | |
public ArrayConstructorExtension(object a, object b, object c, object d) => _elements = new[] { a, b, c, d }; | |
public ArrayConstructorExtension(object a, object b, object c, object d, object e) => _elements = new[] { a, b, c, d, e }; |
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 WinRT.Interop; | |
public void SetOwnerWindow(StoreContext context, Window window) | |
{ | |
var handle = new WindowInteropHelper(window).Handle; | |
InitializeWithWindow.Initialize(context, handle); | |
} |
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 WinRT; | |
public void SetOwnerWindow(StoreContext context, Window window) | |
{ | |
var handle = new WindowInteropHelper(window).Handle; | |
var initWindow = context.As<IInitializeWithWindow>(); | |
initWindow.Initialize(handle); | |
} |