feat: add demo.

This commit is contained in:
rabbitism
2024-03-01 00:12:19 +08:00
parent 2af11dea7e
commit 4d1d45579a
10 changed files with 99 additions and 11 deletions

View File

@@ -0,0 +1,25 @@
<ResourceDictionary xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:u="https://irihi.tech/ursa">
<!-- Add Resources Here -->
<ControlTheme x:Key="{x:Type u:Breadcrumb}" TargetType="u:Breadcrumb">
<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="Template">
<ControlTemplate TargetType="u:BreadcrumbItem">
<Border BorderBrush="Red" BorderThickness="2" Margin="4">
<StackPanel Orientation="Horizontal">
<ContentPresenter Content="{TemplateBinding Icon}" />
<ContentPresenter Name="PART_ContentPresenter" Content="{TemplateBinding Content}"/>
</StackPanel>
</Border>
</ControlTemplate>
</Setter>
</ControlTheme>
</ResourceDictionary>

View File

@@ -4,6 +4,7 @@
<ResourceInclude Source="Badge.axaml" />
<ResourceInclude Source="Banner.axaml" />
<ResourceInclude Source="ButtonGroup.axaml" />
<ResourceInclude Source="Breadcrumb.axaml" />
<ResourceInclude Source="ControlClassesInput.axaml" />
<ResourceInclude Source="Dialog.axaml" />
<ResourceInclude Source="DialogShared.axaml" />

View File

@@ -4,6 +4,7 @@ using Avalonia.Controls.Templates;
using Avalonia.Data;
using Avalonia.Layout;
using Avalonia.Metadata;
using Irihi.Avalonia.Shared.Helpers;
namespace Ursa.Controls;
@@ -47,6 +48,15 @@ public class Breadcrumb: ItemsControl
get => GetValue(SeparatorProperty);
set => SetValue(SeparatorProperty, value);
}
public static readonly StyledProperty<IDataTemplate?> IconTemplateProperty = AvaloniaProperty.Register<Breadcrumb, IDataTemplate?>(
nameof(IconTemplate));
public IDataTemplate? IconTemplate
{
get => GetValue(IconTemplateProperty);
set => SetValue(IconTemplateProperty, value);
}
static Breadcrumb()
{
@@ -66,20 +76,23 @@ public class Breadcrumb: ItemsControl
protected override void PrepareContainerForItemOverride(Control container, object? item, int index)
{
base.PrepareContainerForItemOverride(container, item, index);
if (container is BreadcrumbItem breadcrumbItem)
if (container is not BreadcrumbItem breadcrumbItem) return;
if (!breadcrumbItem.IsSet(BreadcrumbItem.SeparatorProperty))
{
if (!breadcrumbItem.IsSet(BreadcrumbItem.SeparatorProperty))
SeparatorProperty.Changed.AddClassHandler<Breadcrumb, object?>((o, e) =>
{
SeparatorProperty.Changed.AddClassHandler<Breadcrumb, object?>((o, e) =>
breadcrumbItem.Separator = e.NewValue.Value switch
{
breadcrumbItem.Separator = e.NewValue.Value switch
{
string s => s,
ITemplate<Control> t => t.Build(),
_ => e.NewValue.Value?.ToString()
};
});
}
string s => s,
ITemplate<Control> t => t.Build(),
_ => e.NewValue.Value?.ToString()
};
});
}
bool b = breadcrumbItem.IsSet(BreadcrumbItem.IconProperty);
if(!breadcrumbItem.IsSet(BreadcrumbItem.IconProperty) && IconBinding != null)
{
breadcrumbItem[!BreadcrumbItem.IconProperty] = IconBinding;
}
}
}

View File

@@ -1,6 +1,7 @@
using System.Windows.Input;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Templates;
namespace Ursa.Controls;
@@ -34,6 +35,15 @@ public class BreadcrumbItem: ContentControl
set => SetValue(CommandProperty, value);
}
public static readonly StyledProperty<IDataTemplate?> IconTemplateProperty = AvaloniaProperty.Register<BreadcrumbItem, IDataTemplate?>(
nameof(IconTemplate));
public IDataTemplate? IconTemplate
{
get => GetValue(IconTemplateProperty);
set => SetValue(IconTemplateProperty, value);
}
static BreadcrumbItem()
{