问题
I have build a little app that uses AvalonDock 2. I bound my view models to the docking manager, can create and remove documents, all fine. However, there is one thing I do net get to work: When I have multiple documents open I am not able to make a specific document tab the active and visible tab (like if I would click on the tab header) from code.
I have bound to the "ActiveContent" property and set it to the document I want to be the active and visible one, but that does not help.
Can please someone give me some advice on how to do that?
回答1:
After some research it turned out to be a trivial task. The actual problem is lack of documentation on such trivial tasks. So here for all others who fight with the same problem, the answer:
Each LayoutItem has a property named IsSelected
. By setting its value to 'true', the tab representing the LayoutItem is switched into view.
回答2:
Here is a non MMVM solution to making a Layout the active or selected layout in AvalonDock 2.
Code below written in the same class as your XAML MainWindow where "mainPanel" is the name of your LayoutDocumentPane.
XAML
<xcad:LayoutDocumentPane x:Name="mainPanel">
Code Behind:
public void MakeActiveLayout(String layoutTitle)
{
foreach (LayoutDocument child in mainPanel.Children)
{
if(child.Title == layoutTitle)
{
child.IsSelected = true;
}
}
}
来源:https://stackoverflow.com/questions/33918513/how-to-switch-between-document-tabs-in-avalondock-2