feat: implement semi style.
This commit is contained in:
@@ -15,6 +15,7 @@ public class BreadcrumbDemoViewModel: ObservableObject
|
||||
new BreadcrumbDemoItem() { Section = "Page 1", Icon = "Page" },
|
||||
new BreadcrumbDemoItem() { Section = "Page 2", Icon = "Page" },
|
||||
new BreadcrumbDemoItem() { Section = "Page 3", Icon = "Page" },
|
||||
new BreadcrumbDemoItem() { Section = "Page 4", Icon = "Page" },
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,36 +1,85 @@
|
||||
<ResourceDictionary xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:u="https://irihi.tech/ursa">
|
||||
<ResourceDictionary
|
||||
xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:u="https://irihi.tech/ursa">
|
||||
<Design.PreviewWith>
|
||||
<StackPanel>
|
||||
<u:Breadcrumb >
|
||||
<TextBlock Text="Hello"></TextBlock>
|
||||
<u:BreadcrumbItem Icon="?" Separator="♥"></u:BreadcrumbItem>
|
||||
<TextBlock Text="Avalonia"></TextBlock>
|
||||
<TextBlock Text="Ursa"></TextBlock>
|
||||
<u:Breadcrumb>
|
||||
<TextBlock Text="Hello" />
|
||||
<u:BreadcrumbItem Content="World" Icon="♥" />
|
||||
<TextBlock Text="Avalonia" />
|
||||
<TextBlock Text="Ursa" />
|
||||
</u:Breadcrumb>
|
||||
</StackPanel>
|
||||
</Design.PreviewWith>
|
||||
<ControlTheme x:Key="{x:Type u:Breadcrumb}" TargetType="u:Breadcrumb">
|
||||
<Setter Property="Separator" Value="/"></Setter>
|
||||
<Setter Property="Separator" Value="/" />
|
||||
<Setter Property="Template">
|
||||
<ControlTemplate TargetType="u:Breadcrumb">
|
||||
<ItemsPresenter ItemsPanel="{TemplateBinding ItemsPanel}" />
|
||||
</ControlTemplate>
|
||||
</Setter>
|
||||
</ControlTheme>
|
||||
|
||||
|
||||
<ControlTheme x:Key="{x:Type u:BreadcrumbItem}" TargetType="u:BreadcrumbItem">
|
||||
<Setter Property="Cursor" Value="Hand"></Setter>
|
||||
<Setter Property="Template">
|
||||
<ControlTemplate TargetType="u:BreadcrumbItem">
|
||||
<Border BorderBrush="Red" BorderThickness="2" Margin="4">
|
||||
<Border Background="Transparent">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<ContentPresenter Content="{TemplateBinding Icon}" ContentTemplate="{TemplateBinding IconTemplate}" />
|
||||
<ContentPresenter Name="PART_ContentPresenter" Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}"/>
|
||||
<ContentPresenter Name="Separator" Content="{TemplateBinding Separator}"></ContentPresenter>
|
||||
<ContentPresenter
|
||||
Name="PART_IconPresenter"
|
||||
Margin="0 0 4 0"
|
||||
VerticalAlignment="Center"
|
||||
Content="{TemplateBinding Icon}"
|
||||
ContentTemplate="{TemplateBinding IconTemplate}"
|
||||
Foreground="{TemplateBinding Foreground}"
|
||||
IsVisible="{TemplateBinding Icon,
|
||||
Converter={x:Static ObjectConverters.IsNotNull}}" />
|
||||
<ContentPresenter
|
||||
Name="PART_ContentPresenter"
|
||||
VerticalAlignment="Center"
|
||||
IsVisible="{TemplateBinding Content,
|
||||
Converter={x:Static ObjectConverters.IsNotNull}}"
|
||||
Foreground="{DynamicResource SemiColorText2}"
|
||||
Content="{TemplateBinding Content}"
|
||||
ContentTemplate="{TemplateBinding ContentTemplate}" />
|
||||
<ContentPresenter Name="Separator" VerticalAlignment="Center" Content="{TemplateBinding Separator}" Foreground="{DynamicResource SemiColorText3}" Margin="4 0">
|
||||
<ContentPresenter.IsVisible>
|
||||
<TemplateBinding Property="Separator" Converter="{x:Static ObjectConverters.IsNotNull}" />
|
||||
</ContentPresenter.IsVisible>
|
||||
</ContentPresenter>
|
||||
</StackPanel>
|
||||
</Border>
|
||||
</ControlTemplate>
|
||||
</Setter>
|
||||
<Style Selector="^:last">
|
||||
<Style Selector="^ /template/ ContentPresenter#PART_IconPresenter">
|
||||
<Setter Property="Foreground" Value="{DynamicResource SemiColorText0}"/>
|
||||
</Style>
|
||||
<Style Selector="^ /template/ ContentPresenter#PART_ContentPresenter">
|
||||
<Setter Property="Foreground" Value="{DynamicResource SemiColorText0}"/>
|
||||
<Setter Property="FontWeight" Value="Bold"/>
|
||||
</Style>
|
||||
<Style Selector="^ /template/ ContentPresenter#Separator">
|
||||
<Setter Property="IsVisible" Value="False"/>
|
||||
</Style>
|
||||
<Style Selector="^:pointerover">
|
||||
<Style Selector="^ /template/ ContentPresenter#PART_IconPresenter">
|
||||
<Setter Property="Foreground" Value="{DynamicResource SemiBlue5}"/>
|
||||
</Style>
|
||||
<Style Selector="^ /template/ ContentPresenter#PART_ContentPresenter">
|
||||
<Setter Property="Foreground" Value="{DynamicResource SemiBlue5}"/>
|
||||
</Style>
|
||||
</Style>
|
||||
</Style>
|
||||
<Style Selector="^:pointerover">
|
||||
<Style Selector="^ /template/ ContentPresenter#PART_IconPresenter">
|
||||
<Setter Property="Foreground" Value="{DynamicResource SemiBlue5}"/>
|
||||
</Style>
|
||||
<Style Selector="^ /template/ ContentPresenter#PART_ContentPresenter">
|
||||
<Setter Property="Foreground" Value="{DynamicResource SemiBlue5}"/>
|
||||
</Style>
|
||||
</Style>
|
||||
</ControlTheme>
|
||||
</ResourceDictionary>
|
||||
|
||||
@@ -56,15 +56,6 @@ public class Breadcrumb: ItemsControl
|
||||
get => GetValue(IconTemplateProperty);
|
||||
set => SetValue(IconTemplateProperty, value);
|
||||
}
|
||||
|
||||
public static readonly StyledProperty<int> MaxItemCountProperty = AvaloniaProperty.Register<Breadcrumb, int>(
|
||||
nameof(MaxItemCount), defaultValue: 4);
|
||||
|
||||
public int MaxItemCount
|
||||
{
|
||||
get => GetValue(MaxItemCountProperty);
|
||||
set => SetValue(MaxItemCountProperty, value);
|
||||
}
|
||||
|
||||
static Breadcrumb()
|
||||
{
|
||||
@@ -84,7 +75,6 @@ public class Breadcrumb: ItemsControl
|
||||
protected override void PrepareContainerForItemOverride(Control container, object? item, int index)
|
||||
{
|
||||
// base.PrepareContainerForItemOverride(container, item, index);
|
||||
if (container == item) return;
|
||||
if (container is not BreadcrumbItem breadcrumbItem) return;
|
||||
if (!breadcrumbItem.IsSet(BreadcrumbItem.SeparatorProperty))
|
||||
{
|
||||
@@ -98,6 +88,10 @@ public class Breadcrumb: ItemsControl
|
||||
breadcrumbItem.Separator = b;
|
||||
});
|
||||
}
|
||||
|
||||
PseudolassesExtensions.Set(container.Classes, BreadcrumbItem.PC_Last, index == ItemCount - 1);
|
||||
|
||||
if (container == item) return;
|
||||
if(!breadcrumbItem.IsSet(ContentControl.ContentProperty))
|
||||
{
|
||||
breadcrumbItem.SetCurrentValue(ContentControl.ContentProperty, item);
|
||||
@@ -106,6 +100,10 @@ public class Breadcrumb: ItemsControl
|
||||
breadcrumbItem[!ContentControl.ContentProperty] = DisplayMemberBinding;
|
||||
}
|
||||
}
|
||||
if (!breadcrumbItem.IsSet(ContentControl.ContentTemplateProperty) && this.ItemTemplate != null)
|
||||
{
|
||||
breadcrumbItem.SetCurrentValue(ContentControl.ContentTemplateProperty, this.ItemTemplate);
|
||||
}
|
||||
if (!breadcrumbItem.IsSet(BreadcrumbItem.IconProperty) && IconBinding != null)
|
||||
{
|
||||
breadcrumbItem[!BreadcrumbItem.IconProperty] = IconBinding;
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
using System.Windows.Input;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.Metadata;
|
||||
using Avalonia.Controls.Templates;
|
||||
|
||||
namespace Ursa.Controls;
|
||||
|
||||
[PseudoClasses(PC_Last)]
|
||||
public class BreadcrumbItem: ContentControl
|
||||
{
|
||||
public const string PC_Last = ":last";
|
||||
public static readonly StyledProperty<object?> SeparatorProperty =
|
||||
AvaloniaProperty.Register<BreadcrumbItem, object?>(
|
||||
nameof(Separator));
|
||||
|
||||
Reference in New Issue
Block a user