views:

87

answers:

1

This is for Silverlight 4, I want to create a new button class for a close/cancel button to use on dataentry screens. The aim is to move the "confirm cancel" interaction to the control rather than having it in the ViewModel. Functional outline:

1) Have a property IsDirty, needs to support binding

2) Has two "states", controled by IsDirty

  • IsDirty = false - Content is "Close"

  • IsDirty = true - Content is "Cancel"

3) When clicked if it is Dirty show a message box to confirm cancel, before calling the command

4) Both states will call the command

Usage would be

<i:CancelButton Command="{Binding Path=CloseCommand}" IsDirty="{Binding Path=IsDirty}"/>

I am looking for pointers, I think a Templated Control would be the best option, but need some guidance on how to do this

A: 

I would seriously think of using a behaviour for this sort of functionality, that way you keep a seperation between the functionality and how it is displayed. Also you can then add the behaviour to other uiitems besides button.

Dimestore Cowboy