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 void GetClose(DependencyObject target)
        {
            return target.GetValue(CloseProperty);
        }

        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>


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.


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.


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


Fiddler and .Net Authentication

October 31, 2006

I had an issue recently with in-line java-script not being rendered using AJAX ASP.NET. So I fire up Fiddler to see whats going on. Only when ever fiddler is open the app no longer works, it throws a WebException complaining that the connection was reset or aborted.

We are using Integrated Authentication on a separate server that the app talks to via web services. It turns out by default Fiddler doesn’t get along with the way .Net Web Services authenticate. It closes any connection that returns a 401.

This article explains the problem and the fix (which is to add a custom rule to fiddler to stop it closing the connection)

http://blogs.newsgator.com/inbox/2006/09/fiddler_and_net.html


Setting Bind Private Path

June 19, 2006

We are messing around with Custom Extensions in Reporting Services. Our extensions bring in a number of DLL's that we regularly update and remove as we play with our new toy. The problem is that invariably we delete one of the DLL's that isn't ours… bye bye Reporting Services. :)

After a couple of attempts and a little searching I found out you can indeed set the private probe path (the path you see displayed as "Intial Private Path" if your looking at fusion logs) The CLR binder will then also check this path for DLL's. Thus allowing you to seperate your DLL's from reporting services'… or any other situation that may be more relevant to you.

Whack this into your app or web config. Also notice that it is relative to the application directory.

<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="bin\ECM"/>
</assemblyBinding>
</runtime>


Raising a bug/suggestion for the .NET Framework

May 10, 2006

Ever wondered how to raise a bug/suggestion for the .NET Framework? I have. And I finally came across it here

http://connect.microsoft.com/feedback/default.aspx?SiteID=210
We encountered a breaking change from 1.1 to 2.0 with the RadioButtonList and raised it here.


$exception; exceptional

May 10, 2006

I have been using Visual Studio 2003 since the first beta. Until today however, I never knew about $exception. This post is a reminder to me that the Locals Window is my friend.

There is a local variable in the locals window when the debugger breaks due to an unhandled exception that holds the thrown exception. I cringe at the thought of time wasted trying to get the same information via other, shall we say less effecient, means.


FileMon and FileLoadException

February 10, 2006

We deal heavily with dynamically created assemblies. We do system installs of our product almost never.
When we do I always encounter the dreaded FileLoadException Setup failed with hr = 0×80070005

For some reason the binder uses an obscure directory that does not have the correct permissions for ASPNET user to access. Which directory? I can never remeber.

Filemon from sysinternals does… it’s great (and free). It shows you all file access commands issued and whether they succeded or not. So its easy to find where your access is being denied.

In this case “c:\documents and settings\Default User\local settings\Application Data”