Key modifiers

Recently I used PInvoke to check if the SHIFT key was pressed while i was doing a drag operation......

what I should have done then and have done now is

 

[code:c#]

if((Keyboard.Modifiers & ModifierKeys.Shift) != ModifierKeys.None)
  Trace.WriteLine("Shift is pressed");

[/code]

A Custom Diagramming Library

Recently I've been working with a 3rd party diagramming library written in windows forms. It's been great and it's pretty fast in building 80% of the application I'm working on.

[Update August 2012: I never got around to doing much with the diagramming library. I opted instead to re-host the visual studio workflow designer for my needs, why I actually considered writing it is beyond me, I’m a campaigner for bolting existing solutions together rather than re-inventing the wheel ]

WPF Data Triggers

Today I needed to control the enabled property of a button "Remove Item" on my form depending on weather there was a selected item in a Listbox.

Here's how

[code:c#]
<Button Content="Remove" Click="OnRemoveTranstion">
<Button.Style>
<Style>
    <Style.Triggers>
        <DataTrigger Binding ="{Binding ElementName=listDetails, Path=SelectedIndex}" Value="-1">
            <Setter Property="Button.IsEnabled" Value="false"/>
        </DataTrigger>
    </Style.Triggers>
</Style>
</Button.Style>
</Button>
[/code]

.NET DateTime Webservices UTC

With .NET 1.1 when we receive a UTC DateTime in a SOAP response from a Webservice it used to get converted to Local time.

With .NET 2.0 when we receive a UTC DateTime in a SOAP response it stays in UTC.

If you need it in local time make sure to call .ToLocalTime()

** Edit: P.s. Have a look at this neat class in the framework XmlConvert