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.Collections.Generic; | |
using System.Diagnostics.CodeAnalysis; | |
using System.Windows; | |
using System.Windows.Media; | |
public static class DependencyObjectExtensions | |
{ | |
public static bool TryFindDescendant<T>(this DependencyObject reference, [NotNullWhen(true)] out T? descendant) where T : DependencyObject | |
{ | |
var queue = new Queue<DependencyObject>(); |
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.Diagnostics; | |
using System.Runtime.InteropServices; | |
internal static class TaskbarHelper | |
{ | |
[DllImport("user32.dll", CharSet = CharSet.Unicode)] | |
extern static IntPtr FindWindow( | |
[MarshalAs(UnmanagedType.LPWStr), In] string lpClassName, | |
[MarshalAs(UnmanagedType.LPWStr), In] string? lpWindowName); |
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 MainWindow : Window | |
{ | |
public MainWindow() | |
{ | |
InitializeComponent(); | |
this.Loaded += OnLoaded; | |
} | |
private async void OnLoaded(object sender, RoutedEventArgs 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 System.Collections.Generic; | |
using System.Linq; | |
using System.Management; | |
public static class MonitorHelper | |
{ | |
public static IEnumerable<MonitorConnection> EnumerateMonitorConnections() | |
{ | |
var @class = new ManagementClass(@"root\wmi:WmiMonitorConnectionParams"); |
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; | |
using System.Globalization; | |
using System.Windows.Data; | |
public class CollectionToBooleanConverter : IValueConverter | |
{ | |
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) | |
{ | |
if (value is IEnumerable collection) |
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.Runtime.InteropServices; | |
using System.Windows; | |
using System.Windows.Interop; | |
using System.Windows.Media; | |
public static class WindowHelper | |
{ | |
public static Point PointToScreen(Visual visual, Point point) | |
{ |
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.Runtime.InteropServices; | |
using System.Windows; | |
using System.Windows.Interop; | |
public static class WindowHelper | |
{ | |
/// <summary> | |
/// Moves a specified Window to the center of a monitor where the cursor locates. | |
/// </summary> |
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 EnumerableExtension | |
{ | |
public static IEnumerable<IGrouping<TSource, TSource>> GroupBy<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> keyFinder) | |
{ | |
if (source is null) | |
throw new ArgumentNullException(nameof(source)); | |
if (keyFinder is null) | |
throw new ArgumentNullException(nameof(keyFinder)); | |
TSource key = default; |
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); |