AvalonDock
AvalonDock copied to clipboard
How can i use different AnchorableTitleTemplate in different LayoutAnchorable ?
I can define two different templates as follows:
avalonDock:DockingManager.Resources <DataTemplate x:Key="DockingWindowTitleDataTemplate" DataType="{x:Type avalonDock:LayoutContent}"> <Grid> <Grid.Style> <Style TargetType="Grid"> <Style.Triggers> <DataTrigger Binding="{Binding Model.IsActive, Mode=OneWay, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type avalonDock:LayoutAnchorableControl}}, FallbackValue=False}" Value="True"> <Setter Property="Background" Value="#d22944"/> <Setter Property="Margin" Value="-2 -8 -30 0"></Setter> <Setter Property="Opacity" Value="1"></Setter> <Setter Property="MaxWidth" Value="2000"></Setter> </DataTrigger> <DataTrigger Binding="{Binding IsKeyboardFocusWithin, Mode=OneWay, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type avalonDock:LayoutFloatingWindowControl}}, FallbackValue=False}" Value="True"> <Setter Property="Background" Value="#d22944"/> <Setter Property="Margin" Value="-2 -8 -30 0"></Setter> <Setter Property="Opacity" Value="1"></Setter> <Setter Property="MaxWidth" Value="2000"></Setter> </DataTrigger> </Style.Triggers> <Setter Property="Background" Value="LightGray"></Setter> <Setter Property="Margin" Value="-2 -8 -30 0"></Setter> <Setter Property="Opacity" Value="0.7"></Setter> <Setter Property="MaxWidth" Value="2000"></Setter> </Style> </Grid.Style> <Label VerticalAlignment="Bottom" Foreground="White" Content="{Binding Title}"></Label> </Grid> </DataTemplate>
<DataTemplate x:Key="DockingWindowTitleTemplate" DataType="{x:Type avalonDock:LayoutContent}">
<Grid>
<Label VerticalAlignment="Bottom" Foreground="White" Content="{Binding Title}"></Label>
<Fluent:ComboBox Width="60" Height="20" Background="#d22944">
<Fluent:CheckBox Header="rr"></Fluent:CheckBox>
<Fluent:CheckBox Header="tt"></Fluent:CheckBox>
<Fluent:CheckBox Header="uu"></Fluent:CheckBox>
</Fluent:ComboBox>
</Grid>
</DataTemplate>
</avalonDock:DockingManager.Resources>
When I'm using it, I can only use one, and I can't specify a template for a single LayoutAnchorable . The way I use it is as follows:
avalonDock:DockingManager.AnchorableTitleTemplate <StaticResource ResourceKey="DockingWindowTitleDataTemplate" /> </avalonDock:DockingManager.AnchorableTitleTemplate>
Hope someone can help me , thanks very much .
My first idea would be to create 1 single style with a trigger on a property like "TAG" and depending on that change the look a bit.
So you can do this by creating a template selector class
I have a DataGridWindowTemplateSelector that checks if I can cast my view model to a specific class or interface and then applies the appropriate template https://github.com/DaxStudio/DaxStudio/blob/master/src/DaxStudio.UI/TemplateSelectors/DataGridWindowTemplateSelector.cs
And then I set the selector as follows in the xmal: with different data templates based on those defined in my TemplateSelector class
<avalondock:DockingManager.AnchorableHeaderTemplateSelector>
<selectors:DataGridWindowTemplateSelector>
<selectors:DataGridWindowTemplateSelector.TraceTemplate>
<DataTemplate>
<your template goes here>
</DataTemplate>
</selectors:DataGridWindowTemplateSelector.TraceTemplate>
<selectors:DataGridWindowTemplateSelector.DefaultTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Content.Title}"/>
</StackPanel>
</DataTemplate>
</selectors:DataGridWindowTemplateSelector.DefaultTemplate>
<selectors:DataGridWindowTemplateSelector.DataGridTemplate>
<DataTemplate>
<your template goes here>
</DataTemplate>
</selectors:DataGridWindowTemplateSelector.DataGridTemplate>
</selectors:DataGridWindowTemplateSelector>
</avalondock:DockingManager.AnchorableHeaderTemplateSelector>