The LayoutManger's ShowDocument method calls OnOpened on the document that calls ShowDocument. However, CreateDocument is intended to return a different document when used as a multiple document manager. The result is, the document that is actually opened is the one that is returned by CreateDocument, but the the OnOpened call is sent to a document that is not actually shown. So I changed the line
and it works in the way that makes sense to me (which might not actually be what was intended).
I am still having an issue where the view's xaml correctly acts like an instance, but the code behind acts like a singleton. For example... I have a button defined in the xaml that is linked to an event handler in code behind. The event handler changes a property in the view model. The result is, only one instance ever gets changed, regardless of which instance's button I click. The instance that gets changed is the one whose button is first clicked. Thereafter, clicking the button on ANY instance only changes the SAME instance again (the one that was previously changed). I'm not a WPF guru, so I'm not sure whether the issue is in SoapBox, AvalonDock, or WPF, or in some way I have something of mine configured. It sounds like it MIGHT be an issue of StaticResource vs DynamicResource. I'm still investigating...
Here's a fairly quick workaround.... I intend to update my CodeProject article (or add another) with a working example.
In the document, add a static method to look up an instance from our document dictionary.
In the view's xaml, add an item that is bound to the view model's memento (hide it if you don't want to see it).
In the code-behind of the view's resource dictionary, add a property whose getter looks up the document.
Then all references to the Model (ahem ViewModel) will look up the correct one.
answered 26 Apr '12, 11:50
For the second part of your question, I assume you're using a
When WPF sees your
You can still do this, but you have to do it like this:
The other, more "normal" way would be to create your View as a
Alternately you can hook the
Thanks for the explanation.
All of the SoapBox examples I've seen do it this way. If there's another way, I'd like to try it.
Actually, the method used in my CodeProject article is to use a ResourceDictionary wrapping a DataContext wrapping a UserControl. That way, you can still get a GUI to edit the control. The code-behind I was referring to was actually in the UserControl. The forum software seems to have difficulty with the formatting in xaml, so here's an abbreviated pseudo-version.
answered 27 Apr '12, 18:11