RAuer wrote:
The root elemnt in the ServerExplorerView has a loaded event. You can hook on that. For further information about wiring events in CM see the Cheatsheet (http://caliburnmicro.codeplex.com/wikipage?title=Cheat%20Sheet&referringTitle=Documentation).
But in my opinion, in this scenario it would make sense to utilize the ViewModel's activated/deactivated events or methods. See
http://caliburnmicro.codeplex.com/wikipage?title=Screens%2c%20Conductors%20and%20Composition&referringTitle=Documentation and take a look at the paragraphs about the interfaces IActivate, IDeactivate and IViewAware, as well as the parts about OnInitialize,
OnActivate, OnDeactivate and OnViewLoaded.
This should give you a starting point!
Roland
So what you're saying in the first part of your answer is that, in my ServerExplorerView, I should have something like this:
<DockPanel x:Name="layoutRoot"
cal:Message.Attach="[Event Loaded] = [Action Loaded($view)]">
...
</DockPanel>
and then in my ServerExplorerViewModel, implement the Loaded method and publish a message which the ShellView subscribes to? I'm not too concerned at this point about adding code to the view's code-behind, as the merging of toolbars is pretty much a UI concern
only. If I ever find the time to implement the ribbon bars in a full-on MVVM way then I could move all that code into the viewmodel, but that's a bit further down the track.
Regarding the second approach, which is your preference, I'm experiencing the following problem. My ShellViewModel implements Conductor<DocumentViewModel>.Collection.OneActive, where DocumentViewModel implements screen, and is bound to a tab control.
The docked panels, such as the ServerExplorerViewModel referred to previously, separate properties on the ShellViewModel. When I derive these view models from PropertyChangedBase, they work OK; however, when I derive them from Screen, they get picked up the
Conductor, even though they don't implement DocumentViewModel.
My view models are:
public class ShellViewModel : Conductor<DocumentViewModel>.Collection.OneActive
{
public ServerExplorerViewModel ServerExplorer // Implementation of INPC
public ClassExplorerViewModel ClassExplorer // Implementation of INPC
}
public class DocumentViewModel : Screen
{
}
public class ServerExplorerViewModel : PropertyChangedBase
{
}
while my ShellView is:
<dxd:LayoutGroup>
<dxd:DocumentGroup ItemsSource="{Binding Path=Items}">
<dxd:LayoutGroup>
<dxd:LayoutPanel>
<ContentControl cal:View.Model="{Binding Path=ServerExplorer}" />
</dxd:LayoutPanel>
<dxd:LayoutPanel>
<ContentControl cal:View.Model="{Binding Path=ClassExplorer}" />
</dxd:LayoutPanel>
</dxd:LayoutGroup>
</dxd:LayoutGroup>
Is the conductor being too greedy and picking up all implementations of IScreen, rather than taking the Conductor<T> type?
|