Skip to content

Instantly share code, notes, and snippets.

View JoshClose's full-sized avatar

Josh Close JoshClose

View GitHub Profile
@JoshClose
JoshClose / Example1.xml
Created November 15, 2011 16:51
Creating a Common Window in WPF
<ControlTemplate TargetType="Window" x:Key="WindowTemplate">
<aero:SystemDropShadowCrome CornerRadius="10" Margin="10">
<Border BorderThickness="1" BorderBrush="Black" Background="White"
CornerRadius="10">
<Border Height="40" Background="#01000000" VerticalAlignment="Top"
CornerRadius="10,10,0,0" MouseLeftButtonDown="DragWindow">
<ContentPresenter />
</Border>
</Border>
</aero:SystemDropShadowCrome>
@JoshClose
JoshClose / Example1.xml
Created November 15, 2011 16:39
Creating a Custom Window in WPF
<Window x:Class="CustomWindow.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:aero="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero"
Title="Window1" Height="300" Width="300">
<Grid>
</Grid>
</Window>
@JoshClose
JoshClose / Criteria.cs
Created November 15, 2011 15:51
The New World of NHibernate
// This:
session.CreateCriteria( typeof( MyClass ) ).Add( Expression.Eq( "Name", name ) );
// Becomes this:
session.CreateCriteria( typeof( MyClass ) ).Add<MyClass>( m => m.Name == name ).List();
@JoshClose
JoshClose / ColorUserType.cs
Created November 15, 2011 15:44
NHibernate Mapping to System.Drawing.Color
public class ColorUserType : IUserType
{
public object Assemble( object cached, object owner )
{
return cached;
}
public object DeepCopy( object value )
{
return value;
@JoshClose
JoshClose / ColorExtensions.cs
Created November 15, 2011 15:21
Changing Color Tint with C#
public static class ColorExtensions
{
/// <summary>
/// Tints the color by the given percent.
/// </summary>
/// <param name="color">The color being tinted.</param>
/// <param name="percent">The percent to tint. Ex: 0.1 will make the color 10% lighter.</param>
/// <returns>The new tinted color.</returns>
public static Color Lighten( this Color color, float percent )
{
@JoshClose
JoshClose / File2.cs
Created November 15, 2011 15:08
How Safe is the Using Block?
var proxy = new MyProxy();
try
{
// Do some work.
proxy.Close();
}
catch( CommunicationException ex )
{
proxy.Abort();
}
@JoshClose
JoshClose / File1.cs
Created November 15, 2011 15:05
NHibernate 2.1 and Unit Testing with MSTest Using MSBuild
[DeploymentItem( @"..\References\NHibernate\NHibernate.ByteCode.LinFu.dll" )]
@JoshClose
JoshClose / File1.cs
Created November 15, 2011 15:02
ASP.NET MVC, Ninject.Web.Mvc and 404’s
protected void Application_Error( object sender, EventArgs e )
{
var exception = Server.GetLastError();
Response.Clear();
var httpException = exception as HttpException;
var routeData = new RouteData();
routeData.Values.Add( "controller", "Error" );
@JoshClose
JoshClose / File1.xml
Created November 15, 2011 05:42
Dynamically Loading Partial Views with the Spark View Engine
<use file="MyPartialView" />
@JoshClose
JoshClose / ScreenShot.cs
Created November 15, 2011 05:38
Programmatically Taking a Full Web Page Screenshot
using System;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows.Forms;
public class ScreenShot
{
[ComImport]
[InterfaceType( ComInterfaceType.InterfaceIsIUnknown )]
[Guid( "0000010d-0000-0000-C000-000000000046" )]