feat: initialize, setup demo. make sure MVVM works.

This commit is contained in:
rabbitism
2024-02-21 02:15:30 +08:00
parent 3247a37105
commit 76da0b3616
16 changed files with 313 additions and 0 deletions

View File

@@ -0,0 +1,61 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Metadata;
using Avalonia.Controls.Presenters;
using Avalonia.Controls.Primitives;
using Avalonia.Controls.Templates;
using Avalonia.Layout;
namespace Ursa.Controls;
[TemplatePart(PART_OverflowPanel, typeof(Panel))]
public class ToolBar: HeaderedItemsControl
{
public const string PART_OverflowPanel = "PART_OverflowPanel";
internal Panel? OverflowPanel { get; private set; }
private static readonly ITemplate<Panel?> DefaultTemplate =
new FuncTemplate<Panel?>(() => new ToolBarPanel() { Orientation = Orientation.Horizontal });
public static readonly StyledProperty<Orientation> OrientationProperty =
StackPanel.OrientationProperty.AddOwner<ToolBar>();
public Orientation Orientation
{
get => GetValue(OrientationProperty);
set => SetValue(OrientationProperty, value);
}
public static readonly StyledProperty<int> BandProperty = AvaloniaProperty.Register<ToolBar, int>(
nameof(Band));
public int Band
{
get => GetValue(BandProperty);
set => SetValue(BandProperty, value);
}
static ToolBar()
{
IsTabStopProperty.OverrideDefaultValue<ToolBar>(false);
ItemsPanelProperty.OverrideDefaultValue<ToolBar>(DefaultTemplate);
OrientationProperty.OverrideDefaultValue<ToolBar>(Orientation.Horizontal);
}
protected override bool NeedsContainerOverride(object? item, int index, out object? recycleKey)
{
return NeedsContainer<Control>(item, out recycleKey);
}
protected override Control CreateContainerForItemOverride(object? item, int index, object? recycleKey)
{
return new ContentPresenter();
}
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
{
base.OnApplyTemplate(e);
OverflowPanel = e.NameScope.Find<Panel>(PART_OverflowPanel);
}
}