Skip to content

Commit 18aa0b5

Browse files
committed
Initial commit
1 parent 79b7621 commit 18aa0b5

17 files changed

+908
-1
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright (c) Files Community
2+
// Licensed under the MIT License.
3+
4+
using Microsoft.UI;
5+
using Microsoft.UI.Xaml;
6+
using Microsoft.UI.Xaml.Controls;
7+
using Microsoft.UI.Xaml.Input;
8+
using Microsoft.UI.Xaml.Markup;
9+
using Microsoft.UI.Xaml.Media;
10+
using Microsoft.UI.Xaml.Shapes;
11+
12+
namespace Files.App.Controls
13+
{
14+
public partial class BreadcrumbBar
15+
{
16+
private void ItemsRepeater_ElementPrepared(ItemsRepeater sender, ItemsRepeaterElementPreparedEventArgs args)
17+
{
18+
if (args.Element is not BreadcrumbBarItem item)
19+
return;
20+
21+
item.SetOwner(this);
22+
}
23+
}
24+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright (c) Files Community
2+
// Licensed under the MIT License.
3+
4+
using CommunityToolkit.WinUI;
5+
using Microsoft.UI;
6+
using Microsoft.UI.Xaml;
7+
using Microsoft.UI.Xaml.Controls;
8+
using Microsoft.UI.Xaml.Input;
9+
using Microsoft.UI.Xaml.Markup;
10+
using Microsoft.UI.Xaml.Media;
11+
using Microsoft.UI.Xaml.Shapes;
12+
13+
namespace Files.App.Controls
14+
{
15+
public partial class BreadcrumbBar : Control
16+
{
17+
[GeneratedDependencyProperty]
18+
public partial object? ItemsSource { get; set; }
19+
20+
[GeneratedDependencyProperty]
21+
public partial object? ItemTemplate { get; set; }
22+
23+
[GeneratedDependencyProperty]
24+
public partial FrameworkElement? RootElement { get; set; }
25+
26+
partial void OnItemsSourceChanged(object? newValue)
27+
{
28+
}
29+
30+
partial void OnItemTemplateChanged(object? newValue)
31+
{
32+
}
33+
}
34+
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
// Copyright (c) Files Community
2+
// Licensed under the MIT License.
3+
4+
using CommunityToolkit.WinUI;
5+
using Microsoft.UI;
6+
using Microsoft.UI.Xaml;
7+
using Microsoft.UI.Xaml.Controls;
8+
using Microsoft.UI.Xaml.Input;
9+
using Microsoft.UI.Xaml.Markup;
10+
using Microsoft.UI.Xaml.Media;
11+
using Microsoft.UI.Xaml.Shapes;
12+
using System;
13+
using Windows.Foundation;
14+
15+
namespace Files.App.Controls
16+
{
17+
// Template parts
18+
[TemplatePart(Name = "PART_ItemsRepeater", Type = typeof(ItemsRepeater))]
19+
public partial class BreadcrumbBar : Control
20+
{
21+
// Constants
22+
23+
private const string TemplatePartName_RootItem = "PART_RootBreadcrumbBarItem";
24+
private const string TemplatePartName_MainItemsRepeater = "PART_MainItemsRepeater";
25+
26+
// Fields
27+
28+
private BreadcrumbBarLayout _itemsRepeaterLayout = null!;
29+
30+
private BreadcrumbBarItem? _rootItem;
31+
private ItemsRepeater? _itemsRepeater;
32+
33+
// Events
34+
35+
public event TypedEventHandler<BreadcrumbBar, BreadcrumbBarItemClickedEventArgs>? ItemClicked;
36+
public event EventHandler<BreadcrumbBarItemDropDownFlyoutEventArgs>? ItemDropDownFlyoutOpening;
37+
public event EventHandler<BreadcrumbBarItemDropDownFlyoutEventArgs>? ItemDropDownFlyoutClosed;
38+
39+
public event EventHandler? RootItemClicked;
40+
public event EventHandler<BreadcrumbBarItemDropDownFlyoutEventArgs>? RootItemDropDownFlyoutOpening;
41+
public event EventHandler<BreadcrumbBarItemDropDownFlyoutEventArgs>? RootItemDropDownFlyoutClosed;
42+
43+
// Constructor
44+
45+
public BreadcrumbBar()
46+
{
47+
DefaultStyleKey = typeof(BreadcrumbBar);
48+
49+
_itemsRepeaterLayout = new(this, 2d);
50+
}
51+
52+
// Methods
53+
54+
protected override void OnApplyTemplate()
55+
{
56+
_rootItem = GetTemplateChild(TemplatePartName_RootItem) as BreadcrumbBarItem
57+
?? throw new MissingFieldException($"Could not find {TemplatePartName_RootItem} in the given {nameof(BreadcrumbBarItem)}'s style.");
58+
_itemsRepeater = GetTemplateChild(TemplatePartName_MainItemsRepeater) as ItemsRepeater
59+
?? throw new MissingFieldException($"Could not find {TemplatePartName_MainItemsRepeater} in the given {nameof(BreadcrumbBar)}'s style.");
60+
61+
_rootItem.SetOwner(this);
62+
_itemsRepeater.Layout = _itemsRepeaterLayout;
63+
64+
_itemsRepeater.ElementPrepared += ItemsRepeater_ElementPrepared;
65+
66+
base.OnApplyTemplate();
67+
}
68+
69+
internal void RaiseItemClickedEvent(BreadcrumbBarItem item)
70+
{
71+
var index = _itemsRepeater?.GetElementIndex(item) ?? throw new ArgumentNullException($"{_itemsRepeater} is null.");
72+
var eventArgs = new BreadcrumbBarItemClickedEventArgs(item, index);
73+
ItemClicked?.Invoke(this, eventArgs);
74+
}
75+
76+
internal void RaiseItemDropDownFlyoutOpening(BreadcrumbBarItem item, MenuFlyout flyout)
77+
{
78+
var index = _itemsRepeater?.GetElementIndex(item) ?? throw new ArgumentNullException($"{_itemsRepeater} is null.");
79+
ItemDropDownFlyoutOpening?.Invoke(this, new(flyout, item, index));
80+
}
81+
82+
internal void RaiseItemDropDownFlyoutClosed(BreadcrumbBarItem item, MenuFlyout flyout)
83+
{
84+
var index = _itemsRepeater?.GetElementIndex(item) ?? throw new ArgumentNullException($"{_itemsRepeater} is null.");
85+
ItemDropDownFlyoutClosed?.Invoke(this, new(flyout, item, index));
86+
}
87+
}
88+
}

0 commit comments

Comments
 (0)