The problemsLets start with the problems we want to solve with our solution Blend Design time support
Resharper binding validation support
No using ServiceLocator, DI only
ViewModels should be testableFrameworks like Magellan solve these sort of issues in other ways, but if you don't want to take on a framework then maybe an approach like this may help you get started.
My approach I find that once you progress past a basic application with simple interactions that often you need views to interact with each other, this could be returning data from a modal dialogue or anything.One thing we are often told is we should develop against interfaces, not implementations. I think this applies to views as well, so lets create an IView interface. public interface IView
{
}Now I want to be able to tell the calling viewmodel if I was cancelled, or possibly return data, so we will create three more interfaces and a few classes:public interface IDialogueView : IView
{
void DialogueDisplayed();
void DialogueClosed();
}public interface IDialogueView<TResult> : IDialogueView
{
event EventHandler<DialogueResultEventArgs<TResult>> Finished;
}public interface IDialogueViewWithoutResult : IDialogueView
{
event EventHandler<DialogueResultEventArgs> Finished;
}public class DialogueResultEventArgs : EventArgs
{
public DialogueResultEventArgs(bool cancelled)
{
Cancelled = cancelled;
} public bool Cancelled { get; private set; } public static DialogueResultEventArgs EmptyResult = new DialogueResultEventArgs(false);
public static DialogueResultEventArgs CancelledResult = new DialogueResultEventArgs(true);
}
Read more: Jake Ginnivan
QR:
Resharper binding validation support
No using ServiceLocator, DI only
ViewModels should be testableFrameworks like Magellan solve these sort of issues in other ways, but if you don't want to take on a framework then maybe an approach like this may help you get started.
My approach I find that once you progress past a basic application with simple interactions that often you need views to interact with each other, this could be returning data from a modal dialogue or anything.One thing we are often told is we should develop against interfaces, not implementations. I think this applies to views as well, so lets create an IView interface. public interface IView
{
}Now I want to be able to tell the calling viewmodel if I was cancelled, or possibly return data, so we will create three more interfaces and a few classes:public interface IDialogueView : IView
{
void DialogueDisplayed();
void DialogueClosed();
}public interface IDialogueView<TResult> : IDialogueView
{
event EventHandler<DialogueResultEventArgs<TResult>> Finished;
}public interface IDialogueViewWithoutResult : IDialogueView
{
event EventHandler<DialogueResultEventArgs> Finished;
}public class DialogueResultEventArgs : EventArgs
{
public DialogueResultEventArgs(bool cancelled)
{
Cancelled = cancelled;
} public bool Cancelled { get; private set; } public static DialogueResultEventArgs EmptyResult = new DialogueResultEventArgs(false);
public static DialogueResultEventArgs CancelledResult = new DialogueResultEventArgs(true);
}
Read more: Jake Ginnivan
QR:
0 comments:
Post a Comment