by Jon Sigfusson
17. March 2011 07:34
Last night I was working on my favorite hobby project Campaign Planner when I came across a situation where I wanted to handle some user interaction in a user control. When editing a path the user needs to be able to set the precise time of a path point. Now the question I posed myself was: How does the control (or the view model class) initiate a dialog with the user?
I did come up with a solution the next day. Say you wanted the dialog with the user to occur in a modal window then the solution must be: The view model (MVVM) must be the initiator. The user control must handle the creation of the dialog window. You can make this happen with a public event on the view model class and having the user control handle the event by creating a modal dialog window.
Another solution would be to expose a property on the view model class that the user control is bound to and can change visual appearance to support a dialog with the user.
In the case of the modal dialog window I did ponder other options, such as letting the view model class event bubble up the view model hierarchy to the main window view model class where I already handle several other user interaction events. But I must admit that while a little code is required in the view (user control) the simplicity of the solution outweighs the cost.
More to come…
761349ae-7964-4388-9680-622d186dc4da|0|.0
Tags:
Programming
by Jon Sigfusson
10. February 2011 07:45
Whenever I start working on a new solution in Visual Studio 2010 there are usually one or two projects based on the default WPF Application project template. Since starting in WPF I have been trying to discover how to bring the MVVM pattern into my work. For some weeks I have started up new projects following the same pattern, and it occurred to me that I should work these patterns into a project template of my own. But others may benefit from this template and you can download it here.
Files downloaded from the Internet are sometimes blocked for security reasons. To remove this block on the downloaded ZIP you right-click the file and select Properties from the context menu. At the bottom you should be able to see a section with the title Security and a button with a text similar to Unblock. I am Danish and run with a Danish version of Windows, which is why I do not know the exact wording.
The contents and the structure of the template can be seen in figure 1.

It uses the classes RelayCommand and ViewModelBase from Josh Smith’s excellent article in MSDN Magazine.
The template is an example on how to bind the ViewModel to the View without using an IoC framework. It also contains an example of how you can implement dialogs in MVVM with only minimal code in the View.
In the future I hope to find the time to create templates with splash, progress dialogs and background processing.
More to come…
2da5b8cd-9fb8-4f76-a0db-cf4b99842cde|0|.0
Tags:
Programming
by Jon Sigfusson
10. February 2011 07:03
I recently wrote a small application to parse IIS log files. There is already an excellent tool from Microsoft to parse log files, but I needed to do some filtering and grouping and then some analysing before displaying a result, and to this end I decided to write a little tool for the job.
The tool has been named IIS Log Parser, but it can be extended to support log files from other sources. You can download the tool here.
This tool is written in WPF in Visual Studio 2010. It follows the MVVM architecture and I hope to find the time to write how I wrote it, but for now you can use Reflector or similar tool to look at the source code. Please observe the copyrights though.
More to come…
97d90e3a-785b-42c1-8b10-1437b0b3f471|0|.0
Tags:
Programming