Skip to content

Commit

Permalink
Merge pull request #199 from BAndysc/master
Browse files Browse the repository at this point in the history
Styleable tab item header
  • Loading branch information
wieslawsoltes authored Jun 10, 2021
2 parents 9059ea5 + ab16d69 commit 7b3997c
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 22 deletions.
26 changes: 26 additions & 0 deletions samples/AvaloniaDemo/App.axaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,34 @@
<Application xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:AvaloniaDemo"
xmlns:idc="using:Dock.Avalonia.Controls"
xmlns:core="using:Dock.Model.Core"
x:Class="AvaloniaDemo.App">
<Application.DataTemplates>
<local:ViewLocator/>
</Application.DataTemplates>
<Application.Styles>
<Style Selector="idc|DocumentControl">
<Setter Property="HeaderTemplate">
<DataTemplate DataType="core:IDockable">
<StackPanel Orientation="Horizontal">
<PathIcon Data="M5 1C3.89543 1 3 1.89543 3 3V13C3 14.1046 3.89543 15 5 15H11C12.1046 15 13 14.1046 13 13V5.41421C13 5.01639 12.842 4.63486 12.5607 4.35355L9.64645 1.43934C9.36514 1.15804 8.98361 1 8.58579 1H5ZM4 3C4 2.44772 4.44772 2 5 2H8V4.5C8 5.32843 8.67157 6 9.5 6H12V13C12 13.5523 11.5523 14 11 14H5C4.44772 14 4 13.5523 4 13V3ZM11.7929 5H9.5C9.22386 5 9 4.77614 9 4.5V2.20711L11.7929 5Z"
Width="16"
Height="16"
Margin="0"/>
<TextBlock Text="{Binding Title}"
VerticalAlignment="Center"
Padding="4,0,0,0" />
</StackPanel>
</DataTemplate>
</Setter>
</Style>
<Style Selector="idc|ToolControl">
<Setter Property="HeaderTemplate">
<DataTemplate DataType="core:IDockable">
<TextBlock Text="{Binding Title}" Padding="2" />
</DataTemplate>
</Setter>
</Style>
</Application.Styles>
</Application>
1 change: 1 addition & 0 deletions src/Dock.Avalonia/Controls/DockControl.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using Avalonia;
using Avalonia.Controls.Primitives;
using Avalonia.Controls.Templates;
using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.Metadata;
Expand Down
25 changes: 14 additions & 11 deletions src/Dock.Avalonia/Controls/DocumentControl.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
<idc:DocumentControl Width="300" Height="400"/>
</Design.PreviewWith>
<Style Selector="idc|DocumentControl">
<Setter Property="HeaderTemplate">
<DataTemplate DataType="core:IDockable">
<TextBlock Text="{Binding Title}" Padding="2" />
</DataTemplate>
</Setter>
<Setter Property="Template">
<ControlTemplate>
<DockPanel x:Name="PART_DockPanel"
Expand All @@ -18,11 +23,6 @@
x:DataType="dmc:IDocumentDock"
x:CompileBindings="True">
<DockPanel.Styles>
<Style Selector="TextBlock.drag">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="VerticalAlignment" Value="Stretch"/>
<Setter Property="HorizontalAlignment" Value="Stretch"/>
</Style>
<Style Selector="Border.panel">
<Setter Property="Margin" Value="0"/>
<Setter Property="Padding" Value="4"/>
Expand Down Expand Up @@ -167,12 +167,11 @@
Orientation="Horizontal"
Spacing="2"
id:DockProperties.IsDragArea="True"
id:DockProperties.IsDropArea="True" >
<StackPanel Orientation="Horizontal"
Margin="2"
TextBlock.FontSize="{DynamicResource DockFontSizeNormal}">
<TextBlock Text="{Binding Title}" Padding="2" />
</StackPanel>
id:DockProperties.IsDropArea="True">
<Panel Margin="2">
<ContentPresenter ContentTemplate="{Binding $parent[idc:DocumentControl].HeaderTemplate}"
Content="{Binding}" />
</Panel>
<Button Height="14"
Width="14"
Command="{Binding Owner.Factory.CloseDockable}"
Expand Down Expand Up @@ -214,6 +213,10 @@
</ControlTemplate>
</Setter>
</Style>
<Style Selector="idc|DocumentControl /template/ TabStrip#PART_TabStrip TabStripItem">
<Setter Property="FontSize" Value="{DynamicResource DockFontSizeNormal}" />
<Setter Property="FontWeight" Value="Normal" />
</Style>
<Style Selector="idc|DocumentControl /template/ TabStrip#PART_TabStrip TabStripItem:pointerover">
<Setter Property="Background" Value="{DynamicResource DockApplicationAccentBrushMed}"/>
<Setter Property="Foreground" Value="{DynamicResource DockApplicationAccentForegroundBrush}" />
Expand Down
20 changes: 18 additions & 2 deletions src/Dock.Avalonia/Controls/DocumentControl.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Avalonia.Controls;
using Avalonia.Controls.Metadata;
using Avalonia.Controls.Primitives;
using Avalonia.Controls.Templates;
using Avalonia.Input;
using Avalonia.Interactivity;
using Dock.Model.Core;
Expand All @@ -14,12 +15,27 @@ namespace Dock.Avalonia.Controls
[PseudoClasses(":active")]
public class DocumentControl : TemplatedControl
{
/// <summary>
/// Define the <see cref="HeaderTemplate"/> property.
/// </summary>
public static readonly StyledProperty<IDataTemplate> HeaderTemplateProperty =
AvaloniaProperty.Register<DocumentControl, IDataTemplate>(nameof(HeaderTemplate));

/// <summary>
/// Define the <see cref="IsActive"/> property.
/// </summary>
public static readonly StyledProperty<bool> IsActiveProperty =
AvaloniaProperty.Register<DocumentControl, bool>(nameof(IsActive));


/// <summary>
/// Gets or sets tab header template.
/// </summary>
public IDataTemplate HeaderTemplate
{
get => GetValue(HeaderTemplateProperty);
set => SetValue(HeaderTemplateProperty, value);
}

/// <summary>
/// Gets or sets if this is the currently active dockable.
/// </summary>
Expand Down Expand Up @@ -47,7 +63,7 @@ private void Pressed(object? sender, PointerPressedEventArgs e)
}
}
}

/// <inheritdoc/>
protected override void OnPropertyChanged<T>(AvaloniaPropertyChangedEventArgs<T> change)
{
Expand Down
20 changes: 12 additions & 8 deletions src/Dock.Avalonia/Controls/ToolControl.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
<idc:ToolControl Width="300" Height="400"/>
</Design.PreviewWith>
<Style Selector="idc|ToolControl">
<Setter Property="HeaderTemplate">
<DataTemplate DataType="core:IDockable">
<TextBlock Text="{Binding Title}" Padding="2" />
</DataTemplate>
</Setter>
<Setter Property="Template">
<ControlTemplate>
<DockPanel x:Name="PART_DockPanel"
Expand All @@ -27,7 +32,6 @@
<Setter Property="BorderBrush" Value="{DynamicResource DockThemeBorderLowBrush}" />
<Setter Property="BorderThickness" Value="1 0 1 0" />
</Style>

<Style Selector="Separator.separator">
<Setter Property="Background" Value="{DynamicResource DockThemeBorderLowBrush}" />
<Setter Property="Height" Value="1" />
Expand Down Expand Up @@ -105,15 +109,15 @@
<DataTemplate DataType="core:IDockable">
<idc:DockableControl TrackingMode="Tab">
<StackPanel x:Name="DragTool"
id:DockProperties.IsDragArea="True"
id:DockProperties.IsDropArea="True"
Background="Transparent"
Orientation="Horizontal"
Spacing="2">
<TextBlock Text="{Binding Title}"
Classes="drag"
Padding="2"
Margin="2" />
Spacing="2"
id:DockProperties.IsDragArea="True"
id:DockProperties.IsDropArea="True">
<Panel Margin="2">
<ContentPresenter ContentTemplate="{Binding $parent[idc:ToolControl].HeaderTemplate}"
Content="{Binding}" />
</Panel>
</StackPanel>
</idc:DockableControl>
</DataTemplate>
Expand Down
18 changes: 17 additions & 1 deletion src/Dock.Avalonia/Controls/ToolControl.axaml.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Avalonia;
using Avalonia.Controls.Primitives;
using Avalonia.Controls.Templates;
using Avalonia.Input;
using Avalonia.Interactivity;
using Dock.Model.Core;
Expand All @@ -11,11 +12,26 @@ namespace Dock.Avalonia.Controls
/// </summary>
public class ToolControl : TemplatedControl
{
/// <summary>
/// Define the <see cref="HeaderTemplate"/> property.
/// </summary>
public static readonly StyledProperty<IDataTemplate> HeaderTemplateProperty =
AvaloniaProperty.Register<ToolControl, IDataTemplate>(nameof(HeaderTemplate));

/// <summary>
/// Gets or sets tab header template.
/// </summary>
public IDataTemplate HeaderTemplate
{
get => GetValue(HeaderTemplateProperty);
set => SetValue(HeaderTemplateProperty, value);
}

/// <inheritdoc/>
protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
{
base.OnAttachedToVisualTree(e);

AddHandler(PointerPressedEvent, Pressed, RoutingStrategies.Tunnel);
}

Expand Down

0 comments on commit 7b3997c

Please sign in to comment.