Skip to content

Instantly share code, notes, and snippets.

@usausa
usausa / Fill.cs
Last active April 14, 2018 07:42
public static unsafe byte[] Fill(this byte[] array, int offset, int length, byte value)
{
if ((length <= 0) || (array == null))
{
return array;
}
fixed (byte* pSrc = &array[offset])
{
*pSrc = value;
@usausa
usausa / MainWindow.xaml
Created February 16, 2018 07:35
Attached property binding
<Window x:Class="WpfApp.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:local="clr-namespace:WpfApp"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<StackPanel>
<Label Content="{Binding Path=Content.(local:ViewProperty.Title), Mode=OneWay, Source={x:Reference Container}}"/>
using System;
using System.Reflection;
using System.Reflection.Emit;
public static class DynamicActivatorFactory
{
private static readonly AssemblyBuilder AssemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(
new AssemblyName("DynamicActivator"),
AssemblyBuilderAccess.Run);
using System;
using System.ComponentModel;
using System.Windows;
using System.Windows.Interactivity;
[TypeConstraint(typeof(FrameworkElement))]
public class UpdateTargetAction : TriggerAction<FrameworkElement>
{
public static readonly DependencyProperty PropertyNameProperty =
DependencyProperty.Register(nameof(PropertyName), typeof(string), typeof(UpdateTargetAction));