Skip to content

Instantly share code, notes, and snippets.

@LGM-AdrianHum
LGM-AdrianHum / ListBoxDataContextCommands.xaml
Created September 3, 2016 00:43
ListBox with Command Binding to Controller rather than the item
<ListBox ItemsSource="{Binding MyDataSource}">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding MySourceItemName}">
<TextBlock.InputBindings>
<MouseBinding MouseAction="LeftDoubleClick"
Command="{Binding DataContext.MyCommand, RelativeSource={RelativeSource AncestorType={x:Type ListBox}}}"
CommandParameter="{Binding MySourceItemId}" />
</TextBlock.InputBindings>
</TextBlock>
@LGM-AdrianHum
LGM-AdrianHum / SmartButton.cs
Created September 3, 2016 03:24
Smart button That Implements Click and Hold.
public class SmartButton : Button
{
private DispatcherTimer _timer;
public int MillisecondsToWait
{
get { return (int)GetValue(MillisecondsToWaitProperty); }
set { SetValue(MillisecondsToWaitProperty, value); }
}
@LGM-AdrianHum
LGM-AdrianHum / ApplicationStartup.cs
Last active March 5, 2019 13:52
Single Instance With Parameter Passing for WPF 4.0
private void Application_Startup(object sender, StartupEventArgs e)
{
if (SingleInstance.IsFirstInstance)
{
SingleInstance.ArgumentsReceived += SingleInstanceParameter;
SingleInstance.ListenForArgumentsFromSuccessiveInstances();
// Do your other app logic
}
else
{
@LGM-AdrianHum
LGM-AdrianHum / MovieWithResolution.cs
Created September 3, 2016 03:31
Regex for a movie with resolution and team information
string data =
@"1941.1981.1080p.WEB-DL.x264.AC3-EVO.mkv
The.Voices.2014.720p.BDRip.x264.AC3-WiNTeaM.avi
13.Sins.2014.1080p.BluRay.DTS.x264-HDS.mkv
A.Million.Ways.to.Die.in.the.West.2014.1080p.WEB-DL.x264.AC3-EVO.mkv
Ant-Man.2015.1080p.BluRay.x264-SPARKS.mkv";
string pattern = @"
^(?<Name>.+?) # Movie Name up to year and resolution
@LGM-AdrianHum
LGM-AdrianHum / RegexMutliEpisode.java
Created September 3, 2016 03:33
Regex For TV Episodes
String[] data = {
"showname.s01e01e02e03.extension",
"showname.s01e01-02-03.extension",
};
Pattern p = Pattern.compile(
"[.]s(?<season>\\d{1,4})e(?<episodes>\\d{1,3}([e-]\\d{1,3})+)[.]",
Pattern.CASE_INSENSITIVE);
for (String input : data){
Matcher m = p.matcher(input);
while (m.find()){
@LGM-AdrianHum
LGM-AdrianHum / AnimatedBorder.xaml
Created October 6, 2016 00:21
Animate A LinearGradient WPF/XAML with DataTrigger
<Border BorderThickness="10" Height="100" Width="100" >
<Border.Resources>
<Style TargetType="Border">
<Setter Property="BorderBrush">
<Setter.Value>
<LinearGradientBrush>
<GradientStop Color="Yellow" Offset="0.0" />
<GradientStop Color="Red" Offset="0.5" />
<GradientStop Color="Yellow" Offset="1.0" />
</LinearGradientBrush>
@LGM-AdrianHum
LGM-AdrianHum / LinearGradientStartPointEndPointAnimate.xaml
Created October 6, 2016 00:24
Animating Linear Gradient Start and End Points
<Storyboard x:Key="NewContentStoryboard">
<PointAnimation Storyboard.TargetProperty="OpacityMask.(LinearGradientBrush.StartPoint)" From="0.5 0" To="0 0.5" Duration="00:00:1" />
<PointAnimation Storyboard.TargetProperty="OpacityMask.(LinearGradientBrush.EndPoint)" From="1 0.5" To="0 0.5" Duration="00:00:1"/>
</Storyboard>
@LGM-AdrianHum
LGM-AdrianHum / AlternateRowColouring.xaml
Created October 6, 2016 00:25
Alternate List Item Row Colouring
<Window.Resources>
<Style TargetType="{x:Type ListBoxItem}">
<Style.Triggers>
<Trigger Property="ItemsControl.AlternationIndex" Value="0">
<Setter Property="Background" Value="#19f39611"></Setter>
</Trigger>
<Trigger Property="ItemsControl.AlternationIndex" Value="1">
<Setter Property="Background" Value="#19000000"></Setter>
</Trigger>
</Style.Triggers>
@LGM-AdrianHum
LGM-AdrianHum / ReflectionControl.cs
Last active October 6, 2016 00:29
Adding Reflection With A WPF Decorator
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
namespace ReflectionControlProject
{
public class ReflectionControl : Decorator
{
private VisualBrush _reflection;
@LGM-AdrianHum
LGM-AdrianHum / PercentageConverter.cs
Last active October 6, 2016 00:32
Used to bind Actualwidths etc in real time to controls... Especially useful with Child Window Resizing.
using System;
using System.Windows.Data;
namespace Converters
{
public class PercentageConverter : IValueConverter
{
public object Convert(object value,
Type targetType,
object parameter,