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 1", Icon = "Page" },
|
||||||
new BreadcrumbDemoItem() { Section = "Page 2", Icon = "Page" },
|
new BreadcrumbDemoItem() { Section = "Page 2", Icon = "Page" },
|
||||||
new BreadcrumbDemoItem() { Section = "Page 3", Icon = "Page" },
|
new BreadcrumbDemoItem() { Section = "Page 3", Icon = "Page" },
|
||||||
|
new BreadcrumbDemoItem() { Section = "Page 4", Icon = "Page" },
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,18 +1,19 @@
|
|||||||
<ResourceDictionary xmlns="https://github.com/avaloniaui"
|
<ResourceDictionary
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns="https://github.com/avaloniaui"
|
||||||
xmlns:u="https://irihi.tech/ursa">
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:u="https://irihi.tech/ursa">
|
||||||
<Design.PreviewWith>
|
<Design.PreviewWith>
|
||||||
<StackPanel>
|
<StackPanel>
|
||||||
<u:Breadcrumb >
|
<u:Breadcrumb>
|
||||||
<TextBlock Text="Hello"></TextBlock>
|
<TextBlock Text="Hello" />
|
||||||
<u:BreadcrumbItem Icon="?" Separator="♥"></u:BreadcrumbItem>
|
<u:BreadcrumbItem Content="World" Icon="♥" />
|
||||||
<TextBlock Text="Avalonia"></TextBlock>
|
<TextBlock Text="Avalonia" />
|
||||||
<TextBlock Text="Ursa"></TextBlock>
|
<TextBlock Text="Ursa" />
|
||||||
</u:Breadcrumb>
|
</u:Breadcrumb>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</Design.PreviewWith>
|
</Design.PreviewWith>
|
||||||
<ControlTheme x:Key="{x:Type u:Breadcrumb}" TargetType="u:Breadcrumb">
|
<ControlTheme x:Key="{x:Type u:Breadcrumb}" TargetType="u:Breadcrumb">
|
||||||
<Setter Property="Separator" Value="/"></Setter>
|
<Setter Property="Separator" Value="/" />
|
||||||
<Setter Property="Template">
|
<Setter Property="Template">
|
||||||
<ControlTemplate TargetType="u:Breadcrumb">
|
<ControlTemplate TargetType="u:Breadcrumb">
|
||||||
<ItemsPresenter ItemsPanel="{TemplateBinding ItemsPanel}" />
|
<ItemsPresenter ItemsPanel="{TemplateBinding ItemsPanel}" />
|
||||||
@@ -21,16 +22,64 @@
|
|||||||
</ControlTheme>
|
</ControlTheme>
|
||||||
|
|
||||||
<ControlTheme x:Key="{x:Type u:BreadcrumbItem}" TargetType="u:BreadcrumbItem">
|
<ControlTheme x:Key="{x:Type u:BreadcrumbItem}" TargetType="u:BreadcrumbItem">
|
||||||
|
<Setter Property="Cursor" Value="Hand"></Setter>
|
||||||
<Setter Property="Template">
|
<Setter Property="Template">
|
||||||
<ControlTemplate TargetType="u:BreadcrumbItem">
|
<ControlTemplate TargetType="u:BreadcrumbItem">
|
||||||
<Border BorderBrush="Red" BorderThickness="2" Margin="4">
|
<Border Background="Transparent">
|
||||||
<StackPanel Orientation="Horizontal">
|
<StackPanel Orientation="Horizontal">
|
||||||
<ContentPresenter Content="{TemplateBinding Icon}" ContentTemplate="{TemplateBinding IconTemplate}" />
|
<ContentPresenter
|
||||||
<ContentPresenter Name="PART_ContentPresenter" Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}"/>
|
Name="PART_IconPresenter"
|
||||||
<ContentPresenter Name="Separator" Content="{TemplateBinding Separator}"></ContentPresenter>
|
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>
|
</StackPanel>
|
||||||
</Border>
|
</Border>
|
||||||
</ControlTemplate>
|
</ControlTemplate>
|
||||||
</Setter>
|
</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>
|
</ControlTheme>
|
||||||
</ResourceDictionary>
|
</ResourceDictionary>
|
||||||
|
|||||||
@@ -57,15 +57,6 @@ public class Breadcrumb: ItemsControl
|
|||||||
set => SetValue(IconTemplateProperty, value);
|
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()
|
static Breadcrumb()
|
||||||
{
|
{
|
||||||
ItemsPanelProperty.OverrideDefaultValue<Breadcrumb>(_defaultPanel);
|
ItemsPanelProperty.OverrideDefaultValue<Breadcrumb>(_defaultPanel);
|
||||||
@@ -84,7 +75,6 @@ public class Breadcrumb: ItemsControl
|
|||||||
protected override void PrepareContainerForItemOverride(Control container, object? item, int index)
|
protected override void PrepareContainerForItemOverride(Control container, object? item, int index)
|
||||||
{
|
{
|
||||||
// base.PrepareContainerForItemOverride(container, item, index);
|
// base.PrepareContainerForItemOverride(container, item, index);
|
||||||
if (container == item) return;
|
|
||||||
if (container is not BreadcrumbItem breadcrumbItem) return;
|
if (container is not BreadcrumbItem breadcrumbItem) return;
|
||||||
if (!breadcrumbItem.IsSet(BreadcrumbItem.SeparatorProperty))
|
if (!breadcrumbItem.IsSet(BreadcrumbItem.SeparatorProperty))
|
||||||
{
|
{
|
||||||
@@ -98,6 +88,10 @@ public class Breadcrumb: ItemsControl
|
|||||||
breadcrumbItem.Separator = b;
|
breadcrumbItem.Separator = b;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PseudolassesExtensions.Set(container.Classes, BreadcrumbItem.PC_Last, index == ItemCount - 1);
|
||||||
|
|
||||||
|
if (container == item) return;
|
||||||
if(!breadcrumbItem.IsSet(ContentControl.ContentProperty))
|
if(!breadcrumbItem.IsSet(ContentControl.ContentProperty))
|
||||||
{
|
{
|
||||||
breadcrumbItem.SetCurrentValue(ContentControl.ContentProperty, item);
|
breadcrumbItem.SetCurrentValue(ContentControl.ContentProperty, item);
|
||||||
@@ -106,6 +100,10 @@ public class Breadcrumb: ItemsControl
|
|||||||
breadcrumbItem[!ContentControl.ContentProperty] = DisplayMemberBinding;
|
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)
|
if (!breadcrumbItem.IsSet(BreadcrumbItem.IconProperty) && IconBinding != null)
|
||||||
{
|
{
|
||||||
breadcrumbItem[!BreadcrumbItem.IconProperty] = IconBinding;
|
breadcrumbItem[!BreadcrumbItem.IconProperty] = IconBinding;
|
||||||
|
|||||||
@@ -1,12 +1,15 @@
|
|||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
using Avalonia;
|
using Avalonia;
|
||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
|
using Avalonia.Controls.Metadata;
|
||||||
using Avalonia.Controls.Templates;
|
using Avalonia.Controls.Templates;
|
||||||
|
|
||||||
namespace Ursa.Controls;
|
namespace Ursa.Controls;
|
||||||
|
|
||||||
|
[PseudoClasses(PC_Last)]
|
||||||
public class BreadcrumbItem: ContentControl
|
public class BreadcrumbItem: ContentControl
|
||||||
{
|
{
|
||||||
|
public const string PC_Last = ":last";
|
||||||
public static readonly StyledProperty<object?> SeparatorProperty =
|
public static readonly StyledProperty<object?> SeparatorProperty =
|
||||||
AvaloniaProperty.Register<BreadcrumbItem, object?>(
|
AvaloniaProperty.Register<BreadcrumbItem, object?>(
|
||||||
nameof(Separator));
|
nameof(Separator));
|
||||||
|
|||||||
Reference in New Issue
Block a user