Skip to content

Instantly share code, notes, and snippets.

View BYJRK's full-sized avatar
🍋
Juicy

ColdWind BYJRK

🍋
Juicy
View GitHub Profile
@BYJRK
BYJRK / ChangeAttachedPropertyAction.cs
Created June 7, 2024 09:32
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 June 27, 2024 01:39
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 August 2, 2023 14:06
Binding SelectedItems
using System;
using System.Collections;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
namespace DataGridView
{
public class MultiSelectorHelper
{
@BYJRK
BYJRK / ValueConverters.NET.Demo.xaml
Created June 28, 2023 13:41
ValueConverters.NET 工具包简单演示代码
<Window x:Class="WpfTutorials.NuGetValueConverters.Views.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:conv="clr-namespace:ValueConverters;assembly=ValueConverters"
Title="登录"
Width="800"
Height="600"
WindowStartupLocation="CenterScreen"
@BYJRK
BYJRK / ToysAlgo.py
Created June 4, 2023 05:32
Child Toy Analysis
from collections import Counter
from itertools import permutations
from matplotlib import pyplot as plt
COLS = 5
ROWS = 6
x1 = 10
x2 = 10
@BYJRK
BYJRK / CollectionItemIndexConverter.cs
Created March 16, 2023 08:59
Two WPF converters used to get the item's index inside a ItemsControl
using System.Collections;
using System.Globalization;
using System.Windows.Data;
class ElementIndexConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
if (values.Length == 2 && values[0] is not null && values[1] is IList items)
return (items.IndexOf(values[0]) + 1).ToString();