Skip to content

Instantly share code, notes, and snippets.

View BYJRK's full-sized avatar
🍋
Juicy

ColdWind BYJRK

🍋
Juicy
View GitHub Profile
@BYJRK
BYJRK / GridAssist.cs
Created December 23, 2024 09:12
Automatically set Grid.Rows and Grid.Columns for children controls of a Grid
using System.Windows;
using System.Windows.Controls;
namespace HowToBetterUtilizeGrid;
static class GridAssist
{
#region AutoRowColumn
public static string GetAutoRowColumn(DependencyObject obj)
@BYJRK
BYJRK / AsyncBarrier.cs
Created August 11, 2024 07:42
AsyncBarrier copied from Microsoft.VisualStudio.Threading
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
public class AsyncBarrier
{
/// <summary>
/// The number of participants being synchronized.
/// </summary>
@BYJRK
BYJRK / DynamicMethodInvoker.cs
Last active March 25, 2025 01:20
Livet Handy Snippets
public static class DynamicMethodInvoker
{
public static void Invoke(object targetObject, string methodName)
{
if (targetObject == null)
throw new ArgumentNullException(nameof(targetObject));
if (methodName == null)
throw new ArgumentNullException(nameof(methodName));
var targetObjectType = targetObject.GetType();
@BYJRK
BYJRK / ChangeAttachedPropertyAction.cs
Last active July 8, 2024 14:11
Change the value of an attached property of a target object with Interaction.Triggers
using Microsoft.Xaml.Behaviors;
using System.ComponentModel;
using System.Reflection;
using System.Windows;
public class ChangeAttachedPropertyAction : TargetedTriggerAction<UIElement>
{
public Type? ClassType
{
get { return (Type)GetValue(ClassTypeProperty); }
@BYJRK
BYJRK / CancelableProcessTask.cs
Last active March 19, 2025 12:14
Wrap a long-running synchronous method into an asynchronous method and provide cancellation functionality.
using System.Diagnostics;
public class CancelableProcessTask
{
private readonly string _filename;
private readonly string _arguments;
private Process? _process;
private TaskCompletionSource? _tcs;
@BYJRK
BYJRK / Simulation.cs
Created April 20, 2024 10:58
Phobia Workshop Simulation With Rx.NET
using var bus = new MessageBus();
bool isCompleted = false;
var reactionDelay = TimeSpan.FromSeconds(0.25);
var timReactionDelay = TimeSpan.FromSeconds(0.3);
var ronnieSilenceThreshold = TimeSpan.FromSeconds(3);
bus.Messages
.Subscribe(
m => $"[{DateTime.Now:mm:ss.fff}] {m.Sender}: {m.Content}".Dump(),
() => isCompleted = true
@BYJRK
BYJRK / GridHelper.cs
Created January 3, 2024 14:06
WPF GridHelper to easily define RowDefinitions and ColumnDefinitions
using System.Windows;
using System.Windows.Controls;
public class GridHelper
{
#region Rows & Columns
public static string GetRows(DependencyObject obj)
{
return (string)obj.GetValue(RowsProperty);
@BYJRK
BYJRK / base.user.css
Created December 1, 2023 06:37
Typora 1.8 New feature "GitHub Style Alerts" Custom Style
.md-alert-text {
font-size: 1rem;
font-weight: 600;
}
.md-alert-text-container::after {
text-transform: uppercase;
position: relative;
bottom: 1px;
}
@BYJRK
BYJRK / ModifyPropValue.cs
Created November 14, 2023 13:07
Ref Object.Property
var demo = new Demo();
demo.FieldValue = 10;
demo.PropValue = 10;
// 修改字段的值
ModifyFieldValue(ref demo.FieldValue, 42);
demo.FieldValue.Dump("Field Value");
// 修改属性的值
// ModifyFieldValue(ref demo.PropValue, 42);
@BYJRK
BYJRK / MultiSelectorHelper.cs
Last active May 22, 2025 13:34
Binding SelectedItems
using System;
using System.Collections;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
namespace DataGridView
{
public class MultiSelectorHelper
{