Code snippets

C# Rect.IsEmpty

In C# System.Windows.Rect.IsEmpty doesn’t return what you think it would.
For example:

Rect r = new Rect();

returns false.

Empty has a special meaning, a value that represents a rectangle with no position or area.
The empty rectangle, which has X and Y property values of PositiveInfinity, and has Width and Height property values of NegativeInfinity.

Avoid mathematical computations involving empty rectangles. Because both X and Y are infinite values, processor operations are severely impaired by these operations.

Comparisons involving these values will not affect application performance.


How to re-raise an event in a WPF adorner

protected override void OnMouseWheel(MouseWheelEventArgs e)

Get a string that has current date time for file name creation

returns "20101216110856"


How to use #ifdef to differentiate 64bit and 32bit

Original Article from http://social.msdn.microsoft.com/Forums/en/vcgeneral/thread/2b24afa3-62ef-42d4-9aff-ca309588289c

If you want to use the _WIN64, _WIN32 macros, list the _WIN64 one first.

#if defined _WIN64

#elif defined _WIN32



_WIN32 is defined for both 32 and 64 bit projects so you know that it will always be defined on a MSVC build.

_WIN64 on the other hand is only defined with a 64 bit compiler. So putting 64 first eliminates the need to check for both at once.

The final else is there for if your code is ever built with a different compiler which doesn’t predefine _WIN32 or _WIN64.

This way you can provide an option for that, but if you know it will never be built besides an MSVC compiler then you can just remove it.

crescens2k – http://c2kblog.blogspot.com/

How to reference C++/CLI Input Library correctly so that it builds on TFS build agent

In your C++/CLI Project,

Go to
   Properties/Configuration Properties/Linker/Input/Additional Dependencies/
      and clear the dependencies if you have specified them.
Go to
   Properties/Common Properties/Framework and References/
      click on Add New Reference and select the files or projects or other assemblies
      click on the newly added reference
         On the right hand pane under Project Reference, set Properties/Link Library Dependencies = true

WPF XAML xmlns: assembly not found problem

Solved by giving the custom Assembly a strong name or in other words sign the assembly.

  1. Goto Project/Properties/Signing
  2. Click “Sign the assembly” and add a key file to the assembly
  3. Rebuild the assembly and the designer will accept the namespace declaration without an error.