Window.Close() from XAML

July 1, 2009

It’s been a long time since I last posted. Since then I have been working on my first WPF contract. I have definately drank the cool aid, I love WPF (when MVVM is being used anyway).

One thing I haven’t been able to find any info on is how to close a window from XAML. I tried and tried and then gave up. Until now!

Having discovered the power of Attached Behaviours, I decided to write one that would close a window. All you need do then is create a data trigger that watches a CloseSignal on the ViewModel and sets the Close property to true.

public static class WindowCloseBehaviour
{
public static void SetClose(DependencyObject target, bool value)
{
target.SetValue(CloseProperty, value);
}
public static readonly DependencyProperty CloseProperty =
DependencyProperty.RegisterAttached(
“Close”,
typeof(bool),
typeof(WindowCloseBehaviour),
new UIPropertyMetadata(false, OnClose));
private static void OnClose(DependencyObject sender, DependencyPropertyChangedEventArgs e)
{
if (e.NewValue is bool && ((bool)e.NewValue))
{
Window window = GetWindow(sender);
if (window != null)
window.Close();
}
}
private static Window GetWindow(DependencyObject sender)
{
Window window = null;
if (sender is Window)
window = (Window)sender;
if (window == null)
window = Window.GetWindow(sender);
return window;
}
}

and then in your XAML

<Style.Triggers>
<DataTrigger Binding=”{Binding CloseSignal}” Value=”true”>
<Setter Property=”Behaviours:WindowCloseBehaviour.Close” Value=”true” />
</DataTrigger>
</Style>


London

January 28, 2009

My extended sabbatical is over and I touch down in London on Thursday. My resume is now posted in the very empty About section.


OpenID

August 13, 2008

The posts here have been few and far between due to my year honeymoon. I just noticed it’s only been 3 months since I found out about OpenID. Already they have some huge sites using it…. I like it.


Coding without comments

August 13, 2008

This is a great post about commenting code. I couldn’t have written it better myself. No really, I couldn’t have. I don’t code in English well. ;)

http://www.codinghorror.com/blog/archives/001150.html


CI Factory

May 4, 2008

Continuous Integration Factory (CI Factory) has just popped up onto my radar and looks fantastic.

Being currently on hiatus and looking to get into the London contracting scene I have been talking to expats about how much pain to expect. Build process comes up time and time again. I’ve heard of builds being manual and taking whole weekends!! So this looks to be a handy tool to have under your belt for getting CI setup quickly.


OpenID

May 4, 2008

Another awesome service that is getting traction is OpenID. OpenID is an online identity service where users sign up once and online applications use OpenID to authenticate.

Microsoft tried this before and failed, thankfully. This seems to be an independent foundation. And as long as it stays so, has my vote.

As a consumer this excites me. While our Toshiba R500 has made life easier by allowing us to connect most login details to my fingerprints. That solution only gets helps us so much (like whenever I’m around the laptop).

There are some obvious issues to overcome when dealing with centralised authentication. I don’t think any are daunting. And some like security are actually blessings in disguise. Like Open Source Software a central authentication system should be theoretically more secure. Instead of relying on the skill sets of a multitude of different teams implementing their own security systems for each application. A team of (hopefully) security experts are able to focus on the thing they do well. And let others focus on making their applications do what they are trying to do.

Convincing business to adopt it will be the real challenge.


XMP InvariantCulture or CurrentCulture

April 5, 2008

Well it wasn’t to be all smooth sailing in my XMP adventure. It turns out dates will always be a problem in life. The BitmapMetadata class has a property DateTaken that is a string! When I copied the date from the backup file to the current file it was swapping the days and months around?

Whats wrong with this i thought?
destMetadata.DateTaken = sourceMetadata.DateTaken;

Download trusty Reflector to the travel laptop and voila!
It turns out the property getter uses DateTime.FromFiletime to get the string. It appears this uses the Current Culture to format the date. The setter parses the passed in value using Convert.ToDateTime(value, CultureInfo.InvariantCulture);

I maybe missing something and I am sure it is by design, but surely they could have used a consistent culture to save me from this? Especially on my honeymoon! :)
DateTime fromDate = Convert.ToDateTime(sourceMetaData.DateTaken, CultureInfo.CurrentCulture);
destMetadata.DateTaken = fromDate.ToString(CultureInfo.InvariantCulture.DateTimeFormat);


A Temporary Hiatus – XMP

April 5, 2008

It’s been about 6 months since I left BluFreeway and took to a life of beaches and relaxation that ones honeymoon brings. :)

The call of coding had nagged me into installing VS 2008 on our lightweight travel laptop to stay afresh of developments in the .NET space. When a small error on my behalf (no prompts for bulk changes in Vista’s Photo Gallery!!) corrupted all the dates of our wedding photos that Kahlia had painstakingly rated, tagged and categorised.

Smiling smugly i said “No Problem!”, knowing all I had to do was whip up some code to copy the dates from the originals we had backed up. A few minutes later I had some code to do such a task. I even knew about EXIF and how to access it. How proud I was off myself knowing all about this graphics stuff! To my dismay the app whilst changing the metadata did nothing towards fixing the problem in Vista. Apparenlty my knowledge was out of date.

Enter Adobes brain child, XMP, a new era in metadata apparently. Thankfully .NET 3.5 has a great set of classes to handle this, WPF. It made the whole process really simple in the end. If only the documentation was as good.

Know it’s back to the sand and surf for awhile yet.


Fade To Blue

October 10, 2007

My time at CampaignMaster is coming to a close after 4.5 years.  Working for PwC when IBM (Big Blue) bought them, I left just after the merger in March 2003. Four and a half years later I am leaving CampaignMaster after Bluefreeway acquired the company (to get married and travel)…. scary.

I though I’d look at the numbers:

  • 1 subversion repositry 
  • 2  Server Locations
  • 3 offices
  • 4y 6m 21 days
  • 9 Developers worked on CM (at different times)
  • 14 blog posts (Huge!)
  • 26 Major Releases
  • 65 project files
  • 3,000 Unit Tests
  • 306,060 lines of code
  • 10 000 000 + emails a month

I’m off for 4-6 months of travel and to get married. Our travels will be blogged about at http://www.chambills.com


Recruitment Sucks

September 21, 2007

The biggest bain of my job by far is recruiting new hires. The market for C# developers in Sydney is very tight at the moment and what seems to be available is not very impressive. So I thought I would compile a list of my many frustrating encounters; both with Candidates and Recruiters.
We are hiring again.. so I’m sure i’ll add more in the future.
Read the rest of this entry »