Reusing ViewModels in a Universal App – Part 5

Wow, its been quite the journey but here we are finally at the end. To restate the previous articles – We took a Windows store app that was coded without a ViewModel.  We refactored the code to have a ViewModel which is placed in a shared location, along with the Model.  The final View has…

0

Reusing ViewModels in a Universal App – Part 4

To restate where part 3 ended – We have migrated all the buttons and TextBox to use the ViewModel.  What is left is the display of the items on the stack and the mode radio buttons. Handling Radio Buttons There are a few different ViewModel patterns which work with RadioButtons. Option #1 – Since RadioButton…

0

Reusing ViewModels in a Universal App – Part 3

To restate where part 2 ended – We took the MyCalc app and created an empty ViewModel class.  We then implemented DelegateCommand so we could expose ICommand objects from the ViewModel.  We used that to create commands for the majority of the buttons and modified the XAML to use them.  This allowed us to remove…

0

Reusing ViewModels in a Universal App – Part 2

To restate where part 1 ended – We have our Windows App, MyCalc, which currently has no ViewModel and instead has all the logic in the View layer.  Which means it can’t be reused for different views, such as one for phone.  Our goal is to move that logic into a shared ViewModel and add…

0

Reusing ViewModels in a Universal App – Part 1

There is an increasing trend for Microsoft platforms to build what is called a “Universal App”.  In its ideal it is an application that you code once, and then it runs on desktop, tablet and phone platforms.  This opportunity introduces new challenges – with a main one being that the different platforms have differences.  Differences…

3

Detecting UI Thread Misuse

One of the challenges in building a UI application is correctly using the UI thread.  This is a shared resource, and so any misuse has the potential to have global application effect. The most common form of misuse is using the UI thread for a long period of time.  In severe cases this causes the…

1

Launching Dialog Windows in Managed MMC Snapins

Launching a child window inside MMC 3.0 from managed code isn’t easy.  Different APIs are required for different circumstances.   I don’t know exactly why this is, but I assume it has something to do with all the tricks MMC does to give each managed snapin its own UI thread, and needing to marshal a…

0

WPF ICommandSource Implementations Leak Memory!

Actually the title of this article should be entitled “How to use WeakEventManager with ICommand implementations”, but the memory leak title is more exciting (and true) Overview Some WPF controls, such as Buttons, are command sources.  A command source has 3 properties, Command, CommandParameter and CommandTarget.  When the control does it’s action (like Click for…

3

WeakEventManager and IWeakEventListener

When my team first starting hitting “memory leaks” due to event handlers we investigated a variety of solutions.  There are many examples on the web for implementing some kind of weak listener – but interestingly almost all of them have some flaw.  In the end we settled on using WeakEventManager and its associated IWeakEventListener interface….

5

Creating Attached Properties And Services

One cool thing about DependencyProperties is the ability to have AttachedDependencyProperties (or Attached Property for short).  Regular properties are defined on a type and exist for instances of that type and sub-classes.  An Attached Property is defined in one type, but can be applied to any instance of DependencyObject. So how does this work?  Well…

1