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.Threading.Tasks; | |
using System.Windows.Interop; | |
using Windows.Storage.Pickers; | |
public static async Task<string?> OpenFileDialog(System.Windows.Window window) | |
{ | |
var picker = new FileOpenPicker() | |
{ | |
ViewMode = PickerViewMode.Thumbnail |
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
<Window x:Class="WpfApp.MainWindow" | |
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | |
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | |
Title="MainWindow" | |
Width="400" Height="200"> | |
<Window.Resources> | |
<Style x:Key="RoundStyle" TargetType="{x:Type Button}"> | |
<Setter Property="Width" Value="100"/> | |
<Setter Property="Height" Value="100"/> | |
<Setter Property="Foreground"> |
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; |