Posted 15 years ago
by Aled Hughes
-
Principal Software Engineer,
Control Techniques Ltd.

Hi,
I came across some unexpected behaviour in implementing a tabbed mdi client app that perhaps you could shed some light on:
In the app, the object passed into the "Content" parameter of the DocumentWindow constructor is actually an instance of a ViewModel class (so no association with UI) and there's a DataTemplate entry in the main application resource dictionary which maps that VM to an actual view class which will derive from FrameworkElement.
Now, say I have two separate instances of the ViewModel class created programmatically, each holding different data and I want to create two document windows in the MDI client, one for each VM. I initially thought that an instance of the View class would get created for each VM (i.e. each doc window tab) but that isn't the case - only one instance is created and the DataContext is changed whenever I switch between the tabs. Because the view holds some local data itself, this behaviour causes some issues.
I worked around the issue by wrapping the VM up in a new ContentControl prior to passing it into the DocumentWindow constructor, and then a unique view instance is created for each tab. However, I'm rather intrigued as to why it was behaving in that way.
Thanks,
aled.
I came across some unexpected behaviour in implementing a tabbed mdi client app that perhaps you could shed some light on:
In the app, the object passed into the "Content" parameter of the DocumentWindow constructor is actually an instance of a ViewModel class (so no association with UI) and there's a DataTemplate entry in the main application resource dictionary which maps that VM to an actual view class which will derive from FrameworkElement.
Now, say I have two separate instances of the ViewModel class created programmatically, each holding different data and I want to create two document windows in the MDI client, one for each VM. I initially thought that an instance of the View class would get created for each VM (i.e. each doc window tab) but that isn't the case - only one instance is created and the DataContext is changed whenever I switch between the tabs. Because the view holds some local data itself, this behaviour causes some issues.
I worked around the issue by wrapping the VM up in a new ContentControl prior to passing it into the DocumentWindow constructor, and then a unique view instance is created for each tab. However, I'm rather intrigued as to why it was behaving in that way.
Thanks,
aled.