A developers toolbox that any mechanic or carpenter would envy – Part 1

Every time i take my car into the garage for repairs I am amazed at the size of the tool boxes and the number of tools each mechanic has. Once, I asked my mechanic, “why do you need so many different tools? Many of them are quite similar.” He said, “We never know what might tool might be needed. Each repair job is different and may require a different tool. Each tool has a different purpose.” I thought about that and remembered the carpenter who had worked on one of my homes. He had various types of hammers and screwdrivers.

In the world of tools there is no one tool that does all things or one size fits all. Each tool has a distinct purposef for which it was made. Carpentry and car mechanics are a lot like software development. As developers we are craftsmen and craftswomen just like that mechanic or carepenter. We build software. We put together lines of code. We need tools to help us in our job also.

When i first began programming back in the mid-eighties there were not a lot of tools available for software developers. I coded in a text editor. I saved my code and then went out to DOS. I compiled the code with a compiler and if no errors were found, I then linked the modules together to produce an .exe. If i wanted a tool i had to pretty much make my own. The internet wasn’t like it is now. In factU didnt use the internet. I used Bulletin Board Services (BBS). I didnt start using the internet until about 1991. As i look back now after almost 30 years in the industry if I had the tools I have today and the books and the on-line help avaiable to today’s programmers….. Well let’s just say my early programming years would have been different.

Getting back to the subject at hands. Tools. If a carepenter or a mechanic needs a good toolbox, well so do we as software developers. Over the last few years of programming in the dot net world, I have seen and tried a lot of different tools. Some were good and some were well!!!!! Enough said. I am now working on a book and a series of tutorials to show programmers how to write a line of business in WPF/Silverlight using a set of tools and controls I use on a day to day basis. The application will be in C# and use the MVVM framework. But first, I am going to produce a series of articles on the tools we will be using. Each tool will be discussed and analyzed in a different article.

In this first blog I want to list the tools we will be using. Note this is not the only list of tools available. These are the ones I have found to be the best and have helped me to be successful as a developer. Take a look at these tools and try them out. If you are not happy then try another and another until you find the ones you love and are comfortable with.

Here is my list: Now first off I must issue a disclaimer, I am an independent contractor. I do not work or make any income from any of these companies. They did not ask me or pay me to say or write these things I approached them and some gave me free copies to work with in return. They gave me access to support and advice. So this is my unbiased opinion. It is a given that we will use Visual Studio 2012 and C#. We will use the dot net 4.5 framework. I am not planning to cover smart devices or Win RT at this point. So here is my list. I will just provide a brief statement as to what the tool does in this blog and in the succeeding blogs, I will discuss the tool in more detail.

1. Intersoft WebUI Studio 2012 R2 – This software will be used for the UI controls in WPF/Silverlight and for the MVVM framework.
2. IdeaBlade DevForce 2012 – This will provide us with the Entity Framework. We will use this software for relational mapping and linq
3. TypeMock Isolator V7 / NUnit – This software will be part of the unit testing along with NUnit.
4. NDepend version 4 – This software is a little like a Swiss army knife. It has many uses. It does build compares and differences, code quality and code metrics, analysis of code and finding references down to the function level and dependencies between modules and much more.
5. Red-Gate Memory and Performance Profiler – These two tools we will discuss together. They will help us to detect memory usage and leaks, the performance of our application and the detection of bottlenecks.
6. Red-Gate SmartAssembly – This software will provide for Automated Error Reporting.
7. XAML Spy – This software will be used to debug our XAML.
8. Red-Gate .Net Reflector – Tnis software allows us to look inside any .net code.

This is not a complete list. We may add other tools as we go. In future blogs. we will take a look at each tool in much more detail. We will also discuss the application that we will be creating in more detail. Hope you are as excited about this project as I am. Well, take care and we will see you soon when in part 2, we will discuss the Intersoft Web Studio 2012 R2.


Posted in Uncategorized | Leave a comment

An essential tool for every WPF/Silverlight developer

Last year i blogged about a great product called Silverlight Spy from First Floor Software. Silverlight Spy is an run time inspection tool that allows the developer to exmaine various aspeccts of their Silverlight or Windows Phone 7 application. It provides the ability to visually debug, examine XAML, identify application bottlenecks and understand why the application is behaving as it does. My only complaint about the product was what about all the developers who were developing in WPF? Well back in the summer of 2012, First Floor Software answered that question and released XAML Spy. XAML Spy works in Silverlight, WPF, Windows Phone, and WinRT. In addition, it also works with Windows Surface. It is now the upgrade to Silverlight Spy. Think of it as Silverlight Spy promoted to new platforms. It has all the wonderful capibilities of Silverlight Spy and works on additional platforms.

Over this next year, I place to blog about my experience developing a line of business application in WPF using IdeaBlade Devforce and Intersoft ClientUI tools. I plan to blog also on how to use XAML Spy to reduce development and debugging time. I am a firm believer that XAML Spy is a necessary tool in every Silverlight/WPF/Windows Phone developers toolbox. I can honestly say that using XAML Spy will make the development and debugging process easier and reduce the amount of time needed to make the product ready for release. And isn’t that the goal that as developers we try strive for? First Floor Software has made a valuable but yet affordable product that no developer should be without.

While I will cover in more detail in later blogs the features of XAML Spy, let me enumerate some of my favorite ones. XAML Spy povides a much cleaner interface than Silverlight Spy. The developer can now focus on the content of their application much more easily. In addition, it is a separate windows application. This feature alone allows for some great new possibilities. The best new feature is remote debugging. I can use XAML Spy to remotely debug a Windows Phone application running on a Windows Phone. I can also specifiy which emulator I want to use. And to increase speed of debugging XAML Spy uses TCP sockets to connect to the Windows Phone as opposed to HTTP polling as was used by Silverlight Spy. Not only that I can remotely debug Silverlight applications running on MACOS and applications running on a S
urface device

One of the most important things I like about First Floor Software is their frequent updates to this product. Since the initial release in the summer of 2012, the company has come out with 7 updates. As a developer this allows me to be confident that I am using a product that is continually being improved and reported bugs are being fixed in a timely manner.

I am not an employee of First Floor Software. I am a developer who is continually looking for ways to improve productivity to reduce my development time and to allow me to get a product more quickly from my development machine to the clients machine.

Posted in Uncategorized | Leave a comment

The world is still here and my application must continue.

Well 12/21/2012 has come and gone. The world is still here and my application still needs to be completed. Fortunately companies like Inersoft (http://www.intersoftpt.com) and IdeaBlade (http://www.ideaBlade were not sitting around awaiting the end of the world but instead were continuing to improve already great products and release versions of their award winning software designed to make my job as a developer easier.

I am currently working on creating a database application in .net using SQL Server as the backend. After talking to my users and studying the various options, i decided that a desktop application was to be the main development focus at his time. Since the future might take me down a different path and my application would probably be run over the internet and over other devices such as smart phones and tablets, I wanted to ensure that my application could be easily converted to work on those platforms with the least amount of conversion work. Based on careful consideration of price, ease of use, support, documentation and examples, and releases of updates and fixes, I decided to use Intersoft Client UI for the creation of my user interface and IdeaBlade’s Devforce for the development of the entity framework. I had looked at other UI controls from various companies including ComponentOne, Syncfusion, and Infragistcs. One of the major reasons i chose Intersoft over these other companies was that Intersoft uses the same controls for both WPF and Silverlight. Later as i moved my application from a desktop app to a web based or device based app, it would mean a smoother and faster conversion. In addtion, i found the documentation very helpful and full of examples and tutorials. The Intersoft staff is very helpful and friendly and is always willing to provide assistance to questions posed. I should add that I am not an Intersoft employee but a loyal user of the product. A major decision in developing my application was what framework to use. I decided to use Model View ViewModel (MVVM) as it ties in nicely with the WPF/Silverlight philosophy. The next decision was what MVVM framwork to use. There are a variety out there to choose from including the option to create my own. Using an existing framework while certainly very viable and giving me the benefit of saving me hours of my work. While there are many free ones to choose from it meant one more thing to learn and I felt that many of the existing ones were overkill for what I needed. I know that many developers have strong feelings for their particular favorite MVVM framework. I dont’ want to get into a religious war over which one is the best.

A part of choosing the Intersoft controls was the built in support for MVVM. This feature is not an addon to the controls but is built into the very core of the controls. So I decided to roll my own MVVM framework using the Intersoft UI controls. In the next blog, we will explore the MVVM framework more closely. Now that i had the UI figured out, I needed to work on the interface to the SQL Server database. Again my choices were many. Due again to support, documentation and tutorials, frequent updates, and an ease of usage, I decided to use Devforce 2010 from IdeaBlade. I should also add here that I am not an employee of IdeaBlade.  Devforce would shield my application from the data. The built in object mapper would map my classes to the tables in the database and provide easy to learn and use ways to access the data.

One of the major restrictions on the application was that it had to be in .net 4. Many of my clients were still using older operating systems both on the server and work stations and that limited the .net framework to version 4. Over time i will get my clients moved newer operating systerms and  over to .net 4.5 and then update my application accordingly.

Well thats enough introduction. In the next blog we wil begin to discuss design philisophy and how the MVVM framework that i rolled. Over the next few months will take the application from the design phase to the development phase.

Have a happy and safe holidays.

Posted in Uncategorized | Leave a comment

Asynchronous Queries and Coroutines

Have you ever had one of “eureka” days when the light bulb goes on above the head and the code just seems to fall into place. Well I have and it happened when I finally understood coroutines and how to use them with asynchronous queries.

One of the most difficult parts of learning Silverlight is getting used to asynchronous programming. Over they years, I have been accustomed to programming in C#, Visual Basic, c++ etc. I would issue a query to the database for some data, wait for the data to return, and then display the data on the screen for the user. With asynchronous programming, I now issue a query to the database for some data, the program continues execution and displays the screen without waiting for the return of the data. After a period of time, the data is returned and is displayed on the screen. The UI is no longer held up waiting for the data to return.

Now asynchronous programming can present some interesting challenges for the programmer. There may be a slight pause as the data populates the fields on the form. Depending on the amount of data being returned and the speed of the connection, the data may even seen to flow down the form as the fields are being filled in. Most of the problems can be avoided by retrieving the minimum amount of data needed to fill the form or if using a grid, filing the first page.

As I said before, I found asynchronous programming the most difficult part of learning Silverlight. So much so that for the longest time, I created WPF apps just so that I could use synchronous programming. It wasn’t that it was difficult to create asynchronous queries. It is quite easy to do so. Let’s look at an example of how to create an asynchronous query to retrieve inventory items.

In my repository class, I have a method called GetInventoryItems() which takes 3 parameters. The first parameter is a QueryDescriptor object, which contains the filter and sort criteria. We will examine this object in more detail in later code. The second parameter is what to do upon the successful completion of the query, and finally the last parameter indicates what to do for an unsuccessful query.

 public void GetInventoryItems(QueryDescriptor queryDescriptor, Action<IEnumerable<Inventory>> onSuccess, Action<Exception> onFail)

                op =>
                    if (op.CompletedSuccessfully)
                        if (onSuccess != null)
                        if (onFail != null)

In my View Model class, I have a FetchInventoryItems() method that calls the repository method and passes the appropriate arguments.

        private void FetchInventoryItems()
            this.IsBusy = true;

            _queryDescriptor = new QueryDescriptor();
            _queryDescriptor.FilterDescriptors.Add(new FilterDescriptor("Status", FilterOperator.IsEqualTo, "A"));
            _queryDescriptor.SortDescriptors.Add(new SortDescriptor("Description", ListSortDirection.Ascending));


              (items) => // query success
                  this.IsBusy = false;
              (error) => // failed
                  this.IsBusy = false;

        private void ResetInventoryItemsList(IEnumerable<Inventory> inventory)
            inventory.ForEach(c => InventoryItems.Add(c));

In the above method, I instantiate a new queryDescriptor object. I add a new FilterDescription object that filters the retrieved data to items that have an Active status and a SortDescriptor that will retrieve the data in Description order. This queryDescriptor object is passed as the first parameter to the GetInventoryItems() methods, the second argument tells the method to take the returned rows and pass them to a method called ResetInventoryItemsList which populates an ObservableCollection called InventoryItems which is bound to a UXGridView on the UXPage. If there is an error in the data retrieval process, an error message is displayed to the user.

So it was not the process of creating and using asynchronous queries that bothered me. That was easy. What bothered me was that my applications were made up of more than just simple queries. There were complicated processes that required multiple steps to be complicated with multiple queries to complete the process. Unfortunately with asynchronously processing, control returned after the query was submitted and there was no guarantee that the next process would be completed in the order or time needed.

As an example, I have an entity name Batch. It represents a deposit, a batch of payments. Its identity is a BatchNo which it obtains from a table called LocalInfo which has a field names NextBatchNo. When a batch object is created, the creation process must get the next batch number from the table, increment it by 1, write the next batch number back to the table and create the batch object. This is quite a lot to do under asynchronous processing and pretty much impossible, one would think. But thanks to IdeaBlade and Coroutines, it is quite easy to do. Coroutines allow for the batching of multiple asynchronous queries. All of the queries are batched together as a group. I am going to show a practical example of using Coroutines in a line of business application.

From the Batch ListView form, the user clicks on the “Add New Batch” button. The button is bound to a AddCommand in the View Model class. Here is the AddBatch() method.

      private void AddBatch(object parameter)
            this.IsInEditing = true;

              AddedBatchSaved, // Saved callback
              EditorClosed); // Cancelled callback

All data entry is done in a sandbox editor. The job of the sand box editor is to create the dialog box for data entry, associate it with a view model and reports back to the calling view model whether the Save/OK button or cancel button was clicked.

In the BatchEditSandboxEditor class, I have an AddNewBatch() method which will call the create method of the batch and then show the dialog box for data entry.

       public override void AddNewBatch(Action<Batch> onOk, Action onCancel)

            var coop = Coroutine.Start(Repository.CreateBatch);
            coop.Completed += (sender, args) =>
                    if (args.CompletedSuccessfully)
                        var batch = coop.Result as Batch;
                        ShowBatchDialogBox(batch, onOk, onCancel);


In the AddNewBatch() method, I first clear the cache of any existing batches in memory. I then start a new Coroutine method which will wrap the CreateBatch() method in the repository class. After the batch is completely finished with all of its batch processing, the AddNewBatch() method instantiates a batch object from the returned results and then displays the dialog box.

In the repository class is the coroutine method CreateBatch().

        public IEnumerable<INotifyCompleted> CreateBatch()

            var NextBatchOperation = Manager.LocalInfos

            yield return NextBatchOperation;

            LocalInfo li = NextBatchOperation.Results.First();

            var batchNo = li.NextBatchNo;

            Int32? nextBatchNo = batchNo + 1;

            li.NextBatchNo = nextBatchNo;

            var SaveNextBatchOperation = Manager.SaveChangesAsync(new[] {li});
            SaveNextBatchOperation.Completed += (sender, args) =>
                    var savedEntities = args.Entities;
                    var sr = args.SaveResult;
                    var error = args.Exception;

            yield return SaveNextBatchOperation;
            var batch = new Batch()
                    BatchNo = Int32.Parse(batchNo.ToString()),
                    BatchDate = DateTime.Now,
                    UserCd = CommonUser.CurrentUser.UserCd,
                    Office = CommonUser.CurrentUser.Office,
                    Status = "O"

            yield return Coroutine.Return(batch);

A Coroutine method returns a IEnumerable result. A Coroutine method wraps up multiple asynchronus statements. After each asynchronous statement a yield return statement is inserted into the code. The yield return statements returns the query operation from the asynchronous statement. At the end of the method, yield return Coroutine.Return statements returns the results of the method back to the method holding the Coroutine.Start() method. The statements within the Coroutine method are executed as a batch and the method returns only after all the statements are executed.

Here is the dialog box after the batch is created and the sand box instantiates and displays it.

The batch number, has been retrieved from the LocalInfo table, the next batch number is incremented by 1, and and been saved back the LocalInfo table, ready for the next batch to be created.

I hope that this blog about using Coroutines to batch asynchronous queries together has been helpful and will serve as an example for your own applications.

Posted in Uncategorized | Leave a comment

A Sales Invoice application using Intersoft ClientUI and IdeaBlade DevForce – Part 1

Beginning with today’s blog and over the next couple of blogs, we will explore the building of a sales invoice tracking system using Intersoft ClientUI, IdeaBlade DevForce and nested dialog boxes.

I have been a Windows programmer since the early 1990s using both Visual Basic and Visual C++ MFC. I prefer building Windows apps that have a main page with a navigation bar on the left hand side of the main form and a content page on the right hand side that holds a grid of data.

The above screen shot is a typical application that I recently did for a client who wanted to maintain an inventory for entertainment tickets and the tracking of their purchases, sales, and transfers. From the navigation bar on the left, the user can move to any module of the program. The content panel on the right displays the list view of the module. Using the above list view the user can find existing sales invoice by filling in one or more of the criteria fields and clicking on the Find button. The user can then edit or void a sales invoice or the user can add a new sales invoice.

If the user chooses to add a new sales invoice or edit an existing sales invoice, a UXDialogBox is displayed to collect the information. When the user is finished entering data, the dialog box is closed and the user is returned to the list view. Here is a screen shot showing the dialog box for adding and editing data.

A member has the ability to buy multiple sets of tickets from various vendors on the same sales invoice. Therefore, a UXGridView is used to track the various tickets purchased. Rather than using inline editing in the grid for the purchase of the ticket, I display another dialog box on top of this dialog box for the entering of the detail information. After the detail dialog box is closed, the new row is added to the grid and the user can add another item or finish the sale. Here is a screen shot using the nested dialog boxes.

In the next blog, we will discuss the database structure and the classes used to create the application. In future blogs, we will create the project, the views, the view models, and the repository class. By the time we are done, we will a line of business application that has modules for Customers or Members, Inventory, Sales Invoices, and Purchases. This application will be fully functional and Model View View-Model (MVVM) compliant.

Posted in Uncategorized | 2 Comments

Smart Decision, Smart Investment, SmartAssembly

As a software developer, I try to develop software that is user-friendly, cutting edge, and error/bug free. While all three are attainable goals, usually the first two are the easiest to achieve. No many how much time I spend testing my software, it usually ends up in the clients hands in a less than perfect state. I guess I can console myself with the fact that large corpoations with many more testers and dollars spent in the testing phase then I have available deliver sotfware that is still full of bugs. But somehow that reasoning does not go over well with my frustrated clients.

Over the years, I have come to the following conclusions. As softare becomes more complicated and pushes the edges of technology, bugs and errors are an inevitable part of programming. Even if I could, would it be economcially feasible to produce software that has zero bugs and errors? Probably not. Does that mean that I should be satisfied with releasing software that is imperfect? Of course not. It just means that I need to realize that my staff is the first line of testers and the customer in the form of alpha and beta testers is the second line of defense.

Unfortunately, my customers, while a necessary part of the testing process, are also often times more of a hindrance in the testing process instead of a help. While internal testers are diligent in tracking errors and noting the circumstances in which they occur, external testers often forget to write down errors until later. They forget or scramble up the error message received, or forget the circumstance in which the error occured. would it not be not very helpful for debugging purposes to know exactly where the bug or error occured in the code, the state of variables at the time, and then have the user make a detailed record of this infromation. While that may seem like wishful thinking, it can be a reality thanks to a product from Redgate called SmartAssembly and its Automated Error Reporting feature.

This product which works with the latest version of .net actually provdes three very valuable features, code obfuscation, feature usage reporting and automated error reporting (AER). Of the three, my personal favorite is automated error reporting, but hey I also like the feature usage reporting. With the help of AER, my clients now have the ability to become better testers. And the reporting of bugs and errors is now accurate and filled with detailed information that makes it easy to quickly find and fix the errors. And all the client has to do is click a button. If while executing your application, the user receives an exception, they press a button to send error reporting information. In turn, an error report arrives a web service which is then stored in SQL Server. The developer uses SmartAssembly to read the reports, they fix the bug and release a new version. On the part of the client, AER is as easy to use as 1-2-3.

Setting up AER by the developer is also as easy as 1-2-3. The developer creates a new project in Smart Assembly and adds the main assembly of their application to the project. SmartAssembly is great for the client to use not only during beta testing but for a couple of months after the final release of the application. The overhead of SmartAssembly is minimal and will not have adverse affects on the application.

The latest version of SmartAssembly is 6.1. The AER works well with Silverlight 4 apps, Windows Phone 7 apps, and WPF assemblies. If you have ever released software to clients and then have been bombarded by those same clients with phone calls and emails, you will appreciate the error reporting features of SmartAssembly. It will very quickly pay for itself in hours saved trying to find bugs with the little information usually provided by clients.

I will be blogging more about AER as I prepare my latest project for alpha testing over the next couple of months.

I am not an employee of Redgate nor do I benefit financially in any way from blogging about their product. I am a developer who is constantly looking for new ways to more effectively and efficiently spend my time developing software for clients.

Check out SmartAssembly at http://www.redgate.com.

Posted in Uncategorized | Leave a comment

Much Ado about Nothing

While the above heading might refer to the comedy by William Shakespeare about two pairs of lovers in 16th century Sicily, it also describes my feelings about Model View View-Model (MVVM) frameworks. Now before I get accused of blasphemy in the high court of WPF and Silverlight programmers, let me explain myself. For those of you who know me and have read my previous blogs, you know that I am a strong supporter of MVVM. In fact, I believe that no serious WPF or Silverlight application should be written without using the MVVM pattern.

There is a different between the MVVM pattern and MVVM frameworks. The pattern is there to descibe the concepts of how the application should be built and how the various pieces of the application should communicate back and forth. A framework is just a set of software modules that attempt to make using the pattern easier. it is like building a house from scratch or using a pre-fab. Both methods produce a house. Supposedly the pre-fab is easier to build because the pieces are all there in a package and precut with instructions on how to assemble them together. But you pay a price for using the pre-fab, the building process becomes a cookie cutter technique and all the pre-fab houses of the same model look the same. In addition, you are limited to how the house is designed because the pieces are already pre-cut and you receive just what you need and no more.

Now having said all that, last weekend, I began a new Silverlight/WPF project. I thought that I would try using one of the MVVM frameworks to make the programming process easier. Hmmm which one to use? There are many good ones out there and some not so good ones. I looked at three or four of the more popular ones. I noticed several things about each of them. They are all free. Now I have no problem with free. I will gladly take free over spending money any day. But free also means that you get what you pay for. These frameworks are being developed by individuals in their spare time while they have other jobs which pay their salaries and allow them to survive. I could find no evidence of companies developing any of the more popular frameworks. In the past, Microsoft had attempted to develop several frameworks and they swiftly died out leaving developers out on a limb. All of the frameworks are in various stages of development. None are fully functional yet. They are in various stages of being built. None have fully published documentation or full blown real-life examples.

Now don’t get me wrong. I am not putting down any of the frameworks nor the developers working on them. They might work very well for them and their needs. But last weekend showed me that the existing frameworks as is are not for me at this time. Maybe in the furture, if the frameworks become fully functional, the documentation is complete and real life examples are available, I might change my mind and use one. As I tried learning to use the one that I selected, I quickly became frustrated because of the lack of documentation and good examples. I realized that in addition to learning the ins and outs of programming the application design, learning the intricacies of the control set and the entity framework, there would also be a steep learning curve for the framework and my application fits into the framwork. The question that struck me, was it worth it? I decided no. I would build my own “framework”.

Building my own framework did not mean that I was going to develop a framework kit like the ones that I was rejecting. It meant that i would figure out how to use the MVVM pattern without using a framework software kit. Fortunately I had chosen two 3rd party control packages that would make my work easier. For the entity framework and backend services, I am using DevForce Universal from IdeaBlade. For the UI controls, I am using ClientUI from Intersoft. I discovered this toolset last fall and it remains my favorite among WPF/Silverlight controls. In fact, it is the only set of controls in my toolbox for Visual Studio 2010. In the past I have used Infragistics, Syncfusion, ComponentOne, and Telerik. But the Intersoft has all the controls I need. Well, there is one I wish they would create and that is a schedule/Calendar control. But that is beside the point. As for DevForce Universal, there is no way that I would consider creating a database applcation with using it. While there is the Entity Framework from microsoft and various other ORMs like EntitySpaces and Telerik’s ORM, they pale in comparison to DevForce. Using DevForce makes developing the entity model a relatively easy task and makes commmunication with the database server so much easier than having to use WCF-RIA services.

So now I have the UI controls and I have software for developing the entity framework and the backend services. With ClientUI, I am able to build the view classes. With DevForce, I am able to build the data model, the repository class(es), and communicate with the back end through a piece of software called the Business Object Server. Using C# code, I am able to build the view model classes that provide the application state and access the repository for data requests. Now I needed a way to communicate commands from the view class to the view model class. As an example, on the view. I have a Save button.

In the past, when the user had finished entering data on the view and clicked on the Save button, I had a clicked event that was triggered and code in the code behind module that would receive the clicked event, do some initial processing and call a controller method to complete the save process. But that meant that I had code in the view module, even if it was the code behind portion, and the view was tightly bound to the view model. What if I wanted to use the same view model in say a Windows Phone 7 application. My view would have to change to fit the size and controls of the phone, but i would want the code in my view model and calls to the repository to stay the same. But if the view nad view model were tightly bound togehter that might be difficult to do.

Thanks to the foresight of the developers at Intersoft, the answer was right in front of me. All the Intersoft controls are built from the ground up with the MVVM pattern. For example, the UXButton has a commmond property. So in my xaml, my definition of the button includes this syntax

<Intersoft:UXButton Content="Save" Width="80" IsDefault="True" DialogResult="None" Command="{Binding SaveCommand}"/>

In the view model for this view, I have the following code.

public DelegateCommand SaveCommand {get; set;}

In my constructor I instantiate the SaveCommand object.

SaveCommand = new DelegateCommand(Save, CanSave);

Now I create two methods, CanSave() which takes as an argument object parameter and returns a bool and determines if the button is available to the user or disabled. My second method is Save() which returns a void and takes an object parameter as a parameter. This is the method that actually will do the save.

Here is an example from the current project for the CanSave() and Save() methods for the Member class.

       private bool CanSaveMember(object parameter)
            if (_isNewMember && !_isDirty)
                return false;

            if (_requireValidate)
                _lastValidateResult = this.Validate();
                return _lastValidateResult;

            return _lastValidateResult;

        private void SaveMember(object parameter)
            this.IsBusy = true; // make page busy during save
            Repository.Save(SaveSucceeded, SaveFailed);

        private void SaveSucceeded(IEnumerable entities)
            this.IsBusy = false;
            this.MemberEditDialogResult = DialogResult.OK;

        private void SaveFailed(Exception error)
            this.IsBusy = false;

            string message = error == null
                                 ? "Save Cancelled!"
                                 : "Error: " + error.Message;


All of the Intersoft controls have a mechanism for sending a notification to the view model that something has taken place on the view. The View Model listens for the notification, acts upon it and then using the INotifyPropertyChanged interface, the view is alerted that the state has changed in the view model and the view needs to refreshed. Having this pattern built into the controls, I have no code in the code behind class. My view knows nothing about the view model and my view model knows relatively little or nothing about the view. And with the recently added Event Aggregator class from Intersoft, I have pretty much everything that the MVVM frameworks have without the learning curve.

Instead of spending this week learning how to use a framework, I spent this week producing code. In fact, coding the new application along with all the other things that I have to do for the business, I was able to produce about 7,000 lines of code according to the metrics count of the solution. Rather than spending time learning the framework which doesn’t really help me reach my goal of deploying the application, I am 7,000 lines closer to deployment. As I said, maybe in the future, my views about MVVM frameworks will change and I might learn how to use one. In the meantime, I feel they are “much ado about nothing”.

I am not an employee of IdeaBlade or Intersoft. I am the president of a company that develops software for labor unions. I am constanly on the lookout for tools that make my job more productive and efficient. Both IdeaBlade and Intersoft fulfill that purpose. I cannot say enough good things about them. I am proably one of their biggest cheerleaders.

Posted in Uncategorized | 6 Comments