Well, the question is that apparently you can not. I tried overriding OnViewAttached
, finding the parent of my dynamically bound control (ContentControl
), but I was not able to retrieve its parent ( the PanoramaItem
I wanted to make wider).
So after much trial end error I settled on the following solution:
I define my panorama items explicitly in XAML:
<controls:PanoramaItem Header="item1">
<ContentControl x:Name="Control1"/>
</controls:PanoramaItem>
<controls:PanoramaItem Header="Wide Item" Width="700" Orientation="Horizontal">
<ContentControl x:Name="WideControl"/>
</controls:PanoramaItem>
They are also injected into the ViewModel and added to the collection of Items
, inherited from Caliburn's Cunductor
.
Then, I need to make sure that the ViewModel knows about the currently selected item, so the associated view can be activated by CaliburnMicro:
<controls:Panorama Name="MainPanorama"
cal:Message.Attach="[Event SelectionChanged] =
[Action MainPanorama_OnSelectionChanged($eventArgs)]"
SelectedIndex="{Binding ActivePage, Mode=TwoWay}">
I also make sure that the ViewModel receives the SelectionChanged
event, so it knows when to activate the currently visible item.
And finally the trick that makes it all work in ViewModel:
public void MainPanorama_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
{
ActivateItem(Items[ActivePage]);
}