问题
I am currently building a simple UI using AvalonDock2. If i understood correctly, LayoutItemTemplate can be used to set a template for all documents and achorables.
Now here is my issue : I would like to have "hardcoded" anchorables templates. Anchorables all look like this :
<avalonDock:LayoutAnchorable Title="Dialogs"
CanClose="False"
CanHide="False"
CanFloat="False">
<integratorUI:Explorer DataContext="{Binding Path=Editor.ModelsDialogs}"/>
</avalonDock:LayoutAnchorable>
On the other side, my central document pane is being fed documents via
DocumentsSource="{Binding Path=Editor.EditingModelObjects}"
For those documents, it makes sense to have the template set, so i can use a ContentControl and select the appropriate style like so
<Style x:Key="DocumentStyle" TargetType="ContentControl">
<Style.Triggers>
<DataTrigger Binding="{Binding Path=Type}" Value="{x:Static Member=integratorCore:ModelObjectType.Npc}">
<DataTrigger.Setters>
<Setter Property="Template" Value="{StaticResource ResourceKey=NpcViewTemplate}"/>
</DataTrigger.Setters>
</DataTrigger>
<DataTrigger Binding="{Binding Path=Type}" Value="{x:Static Member=integratorCore:ModelObjectType.Room}">
<DataTrigger.Setters>
<Setter Property="Template" Value="{StaticResource ResourceKey=RoomViewTemplate}"/>
</DataTrigger.Setters>
</DataTrigger>
<DataTrigger Binding="{Binding Path=Type}" Value="{x:Static Member=integratorCore:ModelObjectType.Dialog}">
<DataTrigger.Setters>
<Setter Property="Template" Value="{StaticResource ResourceKey=DialogViewTemplate}"/>
</DataTrigger.Setters>
</DataTrigger>
</Style.Triggers>
</Style>
Now the problem is that, setting the LayoutItemTemplate overrides the hardcoded content for my anchorables...
How could I have both hardcoded anchorables and templated documents? Like in the old AvalonDock Versions, or how should I handle this correctly with the new version?
Here is the full DockingManager:
<avalonDock:DockingManager x:Name="dockingManager"
Grid.Row="2"
DocumentsSource="{Binding Path=Editor.EditingModelObjects}"
DocumentClosing="DockingManagerDocumentClosing">
<avalonDock:DockingManager.Theme>
<avalonDock:ExpressionDarkTheme/>
</avalonDock:DockingManager.Theme>
<!--<avalonDock:DockingManager.LayoutItemTemplate>
<DataTemplate>
<ContentControl Style="{StaticResource LayoutItemStyle}" />
</DataTemplate>
</avalonDock:DockingManager.LayoutItemTemplate>-->
<avalonDock:DockingManager.DocumentHeaderTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=Content.Type.Name}"/>
</DataTemplate>
</avalonDock:DockingManager.DocumentHeaderTemplate>
<avalonDock:LayoutRoot>
<avalonDock:LayoutPanel Orientation="Horizontal">
<avalonDock:LayoutAnchorablePane DockWidth="350">
<avalonDock:LayoutAnchorable Title="Dialogs" CanClose="False" CanHide="False" CanFloat="False">
<integratorUI:Explorer DataContext="{Binding Path=Editor.ModelsDialogs}"/>
</avalonDock:LayoutAnchorable>
<avalonDock:LayoutAnchorable Title="NPCs" CanClose="False" CanHide="False" CanFloat="False">
<integratorUI:Explorer DataContext="{Binding Path=Editor.ModelsNpcs}"/>
</avalonDock:LayoutAnchorable>
<avalonDock:LayoutAnchorable Title="Rooms" CanClose="False" CanHide="False" CanFloat="False">
<integratorUI:Explorer DataContext="{Binding Path=Editor.ModelsRooms}"/>
</avalonDock:LayoutAnchorable>
<avalonDock:LayoutAnchorable Title="TileSet" CanClose="False" CanHide="False" CanFloat="False">
<integratorUI:Explorer DataContext="{Binding Path=Editor.ModelsTileSets}"/>
</avalonDock:LayoutAnchorable>
<avalonDock:LayoutAnchorable Title="Zones" CanClose="False" CanHide="False" CanFloat="False">
<integratorUI:Explorer DataContext="{Binding Path=Editor.ModelsZones}"/>
</avalonDock:LayoutAnchorable>
</avalonDock:LayoutAnchorablePane>
<avalonDock:LayoutDocumentPane x:Name="documentPane">
</avalonDock:LayoutDocumentPane>
<avalonDock:LayoutAnchorablePane DockWidth="300">
<avalonDock:LayoutAnchorable Title="Context"
CanClose="False"
CanHide="False"
CanFloat="False">
<TextBox/>
</avalonDock:LayoutAnchorable>
</avalonDock:LayoutAnchorablePane>
</avalonDock:LayoutPanel>
<avalonDock:LayoutRoot.BottomSide>
<avalonDock:LayoutAnchorSide>
<avalonDock:LayoutAnchorGroup>
<avalonDock:LayoutAnchorable Title="Console"
CanClose="False"
CanHide="False"
CanFloat="False">
<TextBlock Text="Test"/>
</avalonDock:LayoutAnchorable>
<avalonDock:LayoutAnchorable Title="Error List"
CanClose="False"
CanHide="False"
CanFloat="False">
<TextBlock Text="Test"/>
</avalonDock:LayoutAnchorable>
</avalonDock:LayoutAnchorGroup>
</avalonDock:LayoutAnchorSide>
</avalonDock:LayoutRoot.BottomSide>
</avalonDock:LayoutRoot>
</avalonDock:DockingManager>
回答1:
You'll want to use a LayoutItemTemplateSelector to have the appropriate template chosen based on a Document, Anchorable or even a specific type of Document or Anchorable.
This example is from the MVVMTestApp in the AvalonDock Source Code.
You can achieve your desired result by interchanging FileViewTemplate for DocumentTemplate and FileStatsViewTemplate for AnchorableTemplate
<avalonDock:DockingManager.LayoutItemTemplateSelector>
<local:PanesTemplateSelector>
<local:PanesTemplateSelector.FileViewTemplate>
<DataTemplate>
<TextBox Text="{Binding TextContent, UpdateSourceTrigger=PropertyChanged}"/>
</DataTemplate>
</local:PanesTemplateSelector.FileViewTemplate>
<local:PanesTemplateSelector.FileStatsViewTemplate>
<DataTemplate>
<StackPanel Orientation="Vertical">
<TextBlock Text="{Binding FileSize}"/>
<TextBlock Text="{Binding LastModified}"/>
<TextBox Text="test"/>
</StackPanel>
</DataTemplate>
</local:PanesTemplateSelector.FileStatsViewTemplate>
</local:PanesTemplateSelector>
</avalonDock:DockingManager.LayoutItemTemplateSelector>
来源:https://stackoverflow.com/questions/18668705/avalondock2-layoutitemtemplate-only-for-documents