It’s Me, Not You
WPF’s bare controls are decent, but not always as robust as people need or want. I initially setup my Shell using the basic Grid component on a Window. Of course I was and still am in the learning phase, but as my project becomes more “real”, I realize that I should probably start using the components that’ll actually be needed once my project hits our production environment.
Since I’ll be using floating panes, I turned to Infragistics. We use their controls in many of our WinForms applications so it seemed logical to use them for my Prism project. I figured this would be easy since Prism can inject views into any control that hosts an ItemControl or ContentControl.
There was a bit of a learning curve to get Infragistics’ Dock Manager to work the way I wanted. Although I was easily able to place ConentControls in the various dock regions, for some reason I couldn’t get the Dock Manager to fill its parent container. This behavior wasn’t expected because the WinForms equivalent did fill in the area as expected. I also followed the Getting Started sample from scratch in a new project and the control didn’t fill…
I did some searching and it looked like others were having the same issue. The post I found was dated 2009 with no answer so I figured that this issue wasn’t resolved. I was pretty irate that the expected behavior wasn’t implemented over a year later. I even went so far as to gripe to the boss about it and asked if I could look at other companies’ components.
After my grumbling session, I took a step back. Infragistics has been in the controls game a long time (remember Sheridan and VB pre .NET?), they couldn’t have let something like this slip. I did some more searching and I found that all I needed was a single property: LayoutMode=”FillContainer”
Open hand facing upwards and forcefully place forehead into hand…
Views, ViewModels, And Events
Not all applications have simple UIs. I have a registered library that handles some of my Region management based on certain requirements. This manager will inject a View+ViewModel into a Region, nothing complicated here. In my ViewModel I subscribe to certain events, which again is nothing complicated.
I noticed something odd when I retrieved data through my application. Every time I retrieved data, the time it took to display multiplied. At first, I thought it was because my View wasn’t being properly removed from my Region. Nope, the ActiveView count is 0 as it should be. I then placed break points in my data layer and found the culprit.
The expected behavior is that if I request data, a new data layer is instantiated, and my data is returned. However, every time I requested data, a data layer was instantiated, and the data was returned, but the previously instantiated data layer never got destroyed and was also retrieving data!
This immediately made me look at the fact that I subscribed to a retrieval event, but never unsubscribed from it. Prism’s event system must have still had a reference to the CallBack and was still calling it. This explained the multiplicative time increase. I ended up having to make sure that my Region manager library unsubscribes from any events when removing Views from my Regions.