Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to select tabs with AvalonDock

Tags:

wpf

avalondock

I'm trying to select tabs (both in a LayoutDocumentPaneGroup and LayoutAnchorablePane) in AvalonDock. This seems like it should be an easy task, but I'm struggling to find any documentation on the subject. So far the best I've gotten is the ability to select the initial tab (see below), but this binding doesn't seem to persist when changing the bound property after the initial load.

    <dock:DockingManager Name="DockingManager" Grid.Row="2" 
                         AnchorablesSource="{Binding Anchorables}" 
                         DocumentsSource="{Binding Documents}" 
                         DocumentClosed="DockingManager_DocumentClosed"
                         DocumentClosing="DockingManager_DocumentClosing"
                         Loaded="DockingManager_Loaded" 
                         MouseUp="DockingManager_MouseUp">
        <dock:DockingManager.LayoutItemContainerStyle>
            <Style TargetType="{x:Type dockctrl:LayoutItem}" >
                <Setter Property="Title" Value="{Binding Model.Title}" />
                <Setter Property="CloseCommand" Value="{Binding Model.CloseCommand}" />
                <Setter Property="CanClose" Value="{Binding Model.CanClose}" />
                <Setter Property="IsSelected" Value="False" />
                <Style.Triggers>
                    <DataTrigger Binding="{Binding Model.Title}" Value="Resources">
                        <Setter Property="IsSelected" Value="True" />
                    </DataTrigger>
                </Style.Triggers>
            </Style>
        </dock:DockingManager.LayoutItemContainerStyle>

        <dock:LayoutRoot>
            <dock:LayoutPanel Orientation="Horizontal">

                <dock:LayoutAnchorablePaneGroup x:Name="leftAnchorableGroup" DockWidth="300" >
                    <dock:LayoutAnchorablePane  />
                </dock:LayoutAnchorablePaneGroup>

                <dock:LayoutPanel Orientation="Vertical">
                    <dock:LayoutPanel Orientation="Horizontal">
                        <dock:LayoutDocumentPaneGroup x:Name="leftDocumentGroup">
                            <dock:LayoutDocumentPane />
                        </dock:LayoutDocumentPaneGroup>
                    </dock:LayoutPanel>
                </dock:LayoutPanel>

            </dock:LayoutPanel>
        </dock:LayoutRoot>
    </dock:DockingManager>

However if I replace these lines:

<Setter Property="IsSelected" Value="False" />
<Style.Triggers>
    <DataTrigger Binding="{Binding Model.Title}" Value="Resources">
        <Setter Property="IsSelected" Value="True" />
    </DataTrigger>
</Style.Triggers>

with:

<Setter Property="IsSelected" Value="{Binding Model.ContentIsSelected" />

...it doesn't work when I change the value of ContentIsSelected. I can see (using Snoop) that the value of ContentIsSelected itself i in fact changing but IsSelected Does not change with it?!

I also found this other question (which lead me down the path of trying to use IsSelected): How to switch between document tabs in AvalonDock 2 However 'm not entirely sure how to programatically access the LayoutItems beyond the bindings in XAML. I tried the DockingManager.GetLayoutItemFromModel() function but could not get it to return anything other than NULL.

How can I select a tab and bring it into view/focus (as if I were clicking the tab with a mouse)?

like image 478
AXG1010 Avatar asked Sep 13 '25 00:09

AXG1010


1 Answers

The solution ended up being that the default binding was not as expected.

<Setter Property="IsSelected" Value="{Binding Model.ContentIsSelected, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
like image 183
AXG1010 Avatar answered Sep 15 '25 16:09

AXG1010