Down Memory Lane with the 7 Link Challenge


Unsurprisingly, Darren Rowse sure knows how to attract attention to his blog with a call for bloggers around the world to join the 7 link challenge. The idea is you answer 7 questions that highlight some of your blog’s highlights.

So here goes…

  • My first post – somewhat ironically, I found out about Darren’s challenge but reading Simone’s list – Simone put me on to using SubText as my blog engine and is mentioned in my, somewhat lame, first ever post.
  • The post I enjoyed writing the most – was in fact one that contained very few words and involved creating a single diagram that I thought captured the core concepts behind the often bewildering WCF – WCF Simplified to a Single Diagram. I was a software architect for long enough that the desire to draw boxes with lines between them was too strong.
  • The post which had a great discussion – would have to be a fantastic post about How To Impress at Your Next Interview where one of my top peeves was a CV with spelling mistakes. Unfortunately the post itself was riddled with typos to the vast amusement of those reading it! I think I’ve updated most of the mistakes but the comments tell the story nicely.
  • A post on someone else’s blog that you wish you had written – I recently read a great response to someone trying to compare Javascript with Silverlight and making a real hash of it. The response was measured and, unlike the other post, accurate – I like reading people who can keep a calm head and not get lost in emotional hype.
  • A post with a title I’m proud of – not sure I actually take any pride in my post titles but I quite like the directness of UISpy – Download it Here! – especially since there was a decidedly non-direct path to finding it. Lots of direct search hits when someone is looking to download it now.
  • A post you wish more people had read -  was hoping that my rumour starting would generate some sort of confirmation from someone… .NET Rocks Duo Coming to New Zealand?
  • My most helpful/visited post – only recently overtaken by The Difference Between “Add Web Reference” and “Add Service Reference” the post that has been read and commented on most would have to be Do You Really Want to be a Development Team Leader

Am convinced I enjoyed that more than you, but hey, it’s my blog ;-)

PS – go Sky , Chris and Kirk

author: Tokes | posted @ Monday, July 26, 2010 2:21 PM | Feedback (0)

MVVM and Confirmation Dialogs


Providing a confirmation dialog is one of those common requirements that aren’t typically covered when you start reading about the MVVM pattern. Here’s an approach that allows you to still make use of Commands, keep your View Model testable, avoid having to put code behind your View and create a reusable approach for all types of dialogs

imageimage

Even if you’ve defined an ICommand property in your View Model it may still be tempting to simply handle the button’s click event, get a reference to the View Model and wrap calling it depending on the result of a simple MessageBox.

private void deleteButton_Click(object sender, RoutedEventArgs e)
{
    MainViewModel viewModel = DataContext as MainViewModel;
 
    MessageBoxResult result = MessageBox.Show("Are you sure...", "Delete Confirmation", MessageBoxButton.OKCancel);
    if (result == MessageBoxResult.OK)
    {
        viewModel.DeleteCommand.Execute(null);
    }
}

Regardless of how you feel about putting code in your View’s code-behind, this approach, has a few drawbacks.

  • You lose the benefit of binding the Button’s Command and CommandParameter properties – for example, your button won’t automatically disable based on the ICommand.CanExecute property and you have to call Execute explicitly.
  • Your View Model can’t force the user to confirm an action – this is business logic that it should ideally be in control of.
  • You can’t easily test this behaviour.

So here’s another approach – a bit more code but once you’ve set it up it’s about the same amount of effort.

First let’s create an Interface that describes how our View Model might work with a dialog.

public interface IDialogService
{
    int Width { get; set; }
    int Height { get; set; }
    void Show(string title, string message, Action<DialogResult> onClosedCallback);
}

The Show method includes a callback method that has a single parameter, DialogResult, (a simple class I created that contains a boolean Result property) for the result of the dialog confirmation. The callback will be called by any class that implements the IDialogService.

Now, a concrete implementation of this interface could look like this (note I haven’t used a MessageBox dialog this time and have referenced a custom ChildWindow),

public class DialogService: IDialogService
{
    public int Width { get; set; }
    public int Height { get; set; }
 
    public void Show(string title, string message, Action<DialogResult> onClosedCallback)
    {
        // Instantiate a custom ChildWindow that contains a message body that we 
        // can set in the constructor
        ConfirmationDialog dialog = new ConfirmationDialog(message);
 
        // Set the title of the dialog
        dialog.Title = title;
        
        // When the dialog is closed we call the callback (if it exists) with the 
        // result.
        dialog.Closed += (s, e) => 
        {
            if (onClosedCallback != null)
            {
                DialogResult result = new DialogResult();
                result.Result = dialog.DialogResult;
                onClosedCallback(result);
            }
        };
 
        dialog.Width = Width;
        dialog.Height = Height;
        dialog.Show();                
 
    }
}

Adding the IDialogService to our View Model’s constructor allows us to inject a DialogService without the View Model needing to know the details or interact with any user interface.

public class MainViewModel : ViewModelBase
    {
 
    IDialogService DialogService { get; set; }
    public MainViewModel(IDialogService dialogService)
    {
        DialogService = dialogService;
        dialogService.Width = 300;
        dialogService.Height = 200;
    }
    ...
}

It’s then pretty easy to create a Command that requires a confirmation dialog.

DelegateCommand _deleteCommand = null;
public DelegateCommand DeleteCommand
{
    get
    {
        if (_deleteCommand == null)
        {
            _deleteCommand = new DelegateCommand()
            {
                ExecuteAction = (p) =>
                {
                    DialogService.Show(
                        "Delete Confirmation",
                        "Are you sure you want to delete this? There's no turning back",
                        (DialogResult result) =>
                        {
                            if (result.Result.Value)
                            {
                                // You can delete now
                            }
                            else
                            {
                                // Don't delete - abort, abort
                            }
                        }
                    );
                }
            };
        }
        return _deleteCommand;
    }
}

You can now reuse this approach throughout your application.

Easy.

Download Example Files

author: Tokes | posted @ Sunday, July 25, 2010 9:23 PM | Feedback (0)

Apple vs Microsoft


Couldn’t agree more with Jeff Blankenburg’s post on the unnecessary hostility towards Microsoft’s Window’s Phone 7 device and the smug arrogance of people towards something that could be really cool – it’s just soooo childish ;-)

image

image

author: Tokes | posted @ Thursday, July 15, 2010 2:42 PM | Feedback (2)

MVVM Uncovered


mvvmcheerleadersGood to see everyone at last night's Silverlight User Group – sorry I had to run out so quickly afterwards and couldn’t stay very long to chat, had an appointment with a Dutchman and didn’t want to disappoint someone from the land of the next World Cup champions – Hup Holland!

Anyway, here are the slides/demos if you want a closer look at what we covered. Demos include,

  • Designer Support
  • Commanding
  • DelegateCommand
  • Validation Approaches
  • Updating UI From Another Thread

Demo/Slides

author: Tokes | posted @ Friday, July 09, 2010 8:58 AM | Feedback (0)

MVVM Uncovered - Presentation


Hey, a heads up if you’re in Wellington NZ, next week then come along to the Silverlight User Group (actually it’s now known as the Wellington Silverlight & Mobile Developers User Group, SLAMD) where I’ll be doing a presentation on MVVM.

Here’s the blurb.

When it comes to presentation design patterns MVVM is perhaps one of the most simple and, certainly for Silverlight (and WPF), the most compelling of the bunch. In fact, Silverlight, WPF, Blend and Visual Studio 2010 all contain features geared towards making MVVM the natural choice. This session will give you an overview of what MVVM is all about, covering topics such as DataBinding, Commanding, Validation, Testing and more...

Here’s the time and place,

Xero,

Level 1, Old Bank Arcade

98 Customhouse Quay

from 6pm on the 8th July.

RSVP to skysigal@xact-solutions.com

author: Tokes | posted @ Friday, July 02, 2010 2:32 PM | Feedback (0)

ASP.Wizard Control Without Tables


I wrote this post almost 2 years ago showing how to use CSS Adapters to control the rendering of server controls that output non compliant HTML (table based ones in particular). I’ve still been getting lots of hits and questions on the post but if you’re using ASP.NET 4.0 there is a way easier approach.

Read about LayoutTemplates here,

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.wizard.layouttemplate.aspx

Cheers

author: Tokes | posted @ Monday, June 28, 2010 8:56 AM | Feedback (0)

.NET Rocks Duo Coming to New Zealand?


Richard and Carl of .NET Rocks fame have dropped a couple of hints in recent shows that they are hoping to come to TechEd 2010 in NZ and Australia. How awesome would that be!

imageIf you haven’t checked out their podcasts they are a great way to keep up with what’s going on in .NET land while sitting on the bus on your daily commute. They are totally passionate about .NET development and that comes through in the shows – highly entertaining and they would be great keynote speakers.

So good luck convincing those making the decisions guys – you’ve got my vote. Nigel – you on the case?

author: Tokes | posted @ Sunday, June 27, 2010 9:03 PM | Feedback (0)

Silverlight 4 - Thanks Hawkes Bay


A good turnout of people at tonight’s Silverlight 4.0 presentation in the Bay and nice to introduce Silverlight to some and share my ideas on where I think it’s taking us and how it’s adding a whole new dimension to the way we can build application over the web and beyond.

Tip of the day – when presenting, never forget your power cable with only 30 minutes left in the battery – not a good look!

imageThanks to the woman in the audience (sorry forgot your name) who luckily had a compatible one – lifesaver!

Here are the slides/demo for those keen to have a play.

author: Tokes | posted @ Thursday, May 27, 2010 8:50 PM | Feedback (0)

The Future of Web Applications?


Was presenting at the Hamilton User Group the other week and spent a bit of time talking about where Silverlight was going and what this could mean for the future of web applications (as opposed to “websites” that are focused predominantly on displaying text and images and don’t require too much user interaction). Microsoft is taking Silverlight in a very different direction to where the likes of Google are heading with their Apps – Google is putting its money on a standards approach, leveraging the promise of HTML 5.0. While there are some truly amazing applications being built within the constraints of the browser and the technology suite it supports (HTML, CSS, JavaScript) there are still other applications that simply can’t be delivered this way and this is where Silverlight comes in. So how has Silverlight evolved and what does this tell us about where it could go? Note I have absolutely no inside knowledge about the realities of Microsoft’s plans, this is all from my own observations.

TheFuture

So over time the dependence on the browser is diminishing and the features of Silverlight and WPF are converging. Somewhat ironic that this model of writing .NET code that can run anywhere is exactly the same road that Java followed with the cross platform Java Runtime – except I guess Microsoft can take it a step further by offering many languages for many platforms.

author: Tokes | posted @ Sunday, May 16, 2010 11:55 PM | Feedback (1)

Silverlight and Web Standards


Here’s a “quote” from someone at work that raises some really interesting questions about the future of web development,

Until Silverlight follows some sort of industry standard I’m not going to bother…

Here are some responses to the thoughts that popped into my head when I read this…

Web Standards Are Important

For someone to make the statement above, and that it is such a common assertion amongst members of the web community, is testament to its importance. They are important for a number of reasons,

  • Access – standards make it possible for vendors to make browsers, screen-readers and other devices that can interpret the meaning and semantics of mark-up. This opens up a whole world of possibilities for innovation across these consuming technologies and encourages a wide availability of content to a range of users.
  • Democratic Evolution – as standards are governed by representatives from various backgrounds, interests, agendas and companies its evolution is not dominated by the views of any one group.

However, I don’t think they are relevant for all types of “applications” that are accessed over the internet.

Differentiating Between Web Sites and Web Applications?

Historically web standards have been focused on encouraging wide and equal access to the information (and services) of web sites. In particular, HTML, is primarily a formatting language that describes how information should be displayed/intpreted on a device – whether that is a computer, a mobile, or via a screen-reader.

I think of web sites being on the far left of a spectrum that ranges from simple static brochure-ware sites to highly interactive applications that leverage the power of a users machine that happen to also be delivered over the web and often via a web browser. Web applications are also referred to as Rich Internet Applications (RIA).

I’m not convinced that the same standards should be applied equally between websites and web applications.

Web Standards Aren’t A Prerequisite for Building Web Applications

It doesn’t necessarily follow that because web standards have their place – and they do – that they should be applied to any technology delivered over the internet. That’s silly.

If you want to build a site based on HTML then you should most definitely follow web standards. However, if you want to build a site based on another technology – go for it! There are, of course, pros and cons but who cares!

Web Standards Can Encourage Mediocrity

I’m often amazed that web designers are often the most fervent supporters of web standards. And when faced with the endless design possibilities of XAML are often dismissive. I listened to a really interesting podcast recently from the .Net Rocks boys interviewing Billy Hollis – he talked about a workshop he did where he handed out a piece of paper and asked the people to sketch out a form that collection some data or performed some function. Most of the users drew a series of rectangles, grid layouts etc. He then handed out another sheet of paper that contained some initially curved, irregular lines and asked the audience to use these lines as part of their design. Many found it really difficult while others loved challenge. It really highlighted how tied we are to the visual paradigms of the day – working with the constraints of HTML/CSS/JS is, in my mind, stifling design innovation. I’d love to see more designers thinking beyond what we see now in web sites and dreaming of brand new ways of engaging and interacting with users. Remember, Avatar – I’m sure there wasn’t a rectangle in sight on their cool wrap-around monitors! And I guarantee they weren’t rendered in HTML.

XAML is an example of an innovation unhindered by standards that opens up a world of other possibilities. Why wouldn’t you embrace this alternative means of delivering information and content to the web?

Silverlight Is Changing The Way We Build Applications

You can do a lot using HTML based web sites – take Xero – it’s one of the best examples of building a rich user experience within the (considerable) limitations of this technology. And it requires a team of highly talented people to maintain compatibility across different browsers, each with subtly different interpretations of the standards.

But, I can imagine a day when building an application does not first start with a decision about whether it will be rendered in a browser (and if so which one) and/or delivered over the internet. Imagine WPF and Silverlight merging into one – you simply open up Visual Studio, File New Application and at some time you configure it to be accessible over the internet (or not). You configure the URL someone points their browser (or something else) to – and that’s it.

In many ways having to deal with the concept of a browser is prohibitive – for RIA’s it actually gets in the way for the users and for Microsoft who have to build plug-ins for multiple browsers and platforms. We now have a silent launcher that effectively allows a you to install a Silverlight application without a browser – let’s hope this is a first step to browser-less web applications.

Web Standards Are Slow!

OK, you’ve heard this before but, waiting for HTML 5.0 to get ratified will be worse than watching the proverbial dry.

Silverlight is up to version 4.0 (April 2010) and was preceded by versions 3.0 (July 2009), 2.0 (October 2008), 1.0 (Sept 2007) – that’s four versions in about 2.5 years!

HTML first got standardised as version 3.2 by W3C in 1996shortly followed by HTML 4.0 (1997) and 4.01 (1999). Since then nothing and latest estimates for 5.0 suggest we may not see the final proposal until (2022). WTF!

I wonder what version Silverlight will be up to in 2022?

So…

In many ways standards do nothing for innovation – standards in this sense are worthless. Web technologies will and should move faster than this. I for one am glad that Silverlight isn’t hampered by Web Standards and wouldn’t want it any other way.

author: Tokes | posted @ Thursday, May 06, 2010 9:27 PM | Feedback (2)