Skip to content

Commit 1f0fb24

Browse files
committed
Initial commit
1 parent 79b7621 commit 1f0fb24

File tree

13 files changed

+634
-1
lines changed

13 files changed

+634
-1
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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 sealed 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+
partial void OnItemsSourceChanged(object? newValue)
24+
{
25+
}
26+
27+
partial void OnItemTemplateChanged(object? newValue)
28+
{
29+
}
30+
}
31+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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 Windows.Foundation;
13+
14+
namespace Files.App.Controls
15+
{
16+
// Template parts
17+
[TemplatePart(Name = "PART_ItemsRepeater", Type = typeof(ItemsRepeater))]
18+
public sealed partial class BreadcrumbBar : Control
19+
{
20+
// Constants
21+
22+
private const string _itemsRepeaterName = "PART_RootItemsRepeater";
23+
24+
// Fields
25+
26+
private ItemsRepeater _itemsRepeater = null!;
27+
private BreadcrumbBarLayout _itemsRepeaterLayout = null!;
28+
29+
// Events
30+
31+
/// <summary>
32+
/// Occurs when an item is clicked in this <see cref="BreadcrumbBar"/> instance.
33+
/// </summary>
34+
public event TypedEventHandler<BreadcrumbBar, BreadcrumbBarItemClickedEventArgs>? ItemClicked;
35+
36+
// Constructor
37+
38+
public BreadcrumbBar()
39+
{
40+
DefaultStyleKey = typeof(BreadcrumbBar);
41+
42+
_itemsRepeaterLayout = new(this);
43+
}
44+
45+
// Methods
46+
47+
protected override void OnApplyTemplate()
48+
{
49+
_itemsRepeater = GetTemplateChild(_itemsRepeaterName) as ItemsRepeater
50+
?? throw new MissingFieldException($"Could not find {_itemsRepeaterName} in the given {nameof(BreadcrumbBar)}'s style.");
51+
52+
//_itemsRepeater.Layout = _itemsRepeaterLayout;
53+
54+
if (ItemsSource is not null)
55+
_itemsRepeater.ItemsSource = ItemsSource;
56+
57+
if (ItemTemplate is not null)
58+
_itemsRepeater.ItemTemplate = ItemTemplate;
59+
60+
base.OnApplyTemplate();
61+
}
62+
}
63+
}
Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
<!-- Copyright (c) Files Community. Licensed under the MIT License. -->
2+
<ResourceDictionary
3+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5+
xmlns:local="using:Files.App.Controls">
6+
7+
<x:Double x:Key="BreadcrumbBarItemHeight">32</x:Double>
8+
9+
<Style BasedOn="{StaticResource DefaultBreadcrumbBarStyle}" TargetType="local:BreadcrumbBar" />
10+
<Style BasedOn="{StaticResource DefaultBreadcrumbBarItemStyle}" TargetType="local:BreadcrumbBarItem" />
11+
12+
<Style x:Key="DefaultBreadcrumbBarStyle" TargetType="local:BreadcrumbBar">
13+
<Setter Property="AutomationProperties.LandmarkType" Value="Navigation" />
14+
<Setter Property="IsTabStop" Value="False" />
15+
<Setter Property="Template">
16+
<Setter.Value>
17+
<ControlTemplate TargetType="local:BreadcrumbBar">
18+
<ItemsRepeater x:Name="PART_RootItemsRepeater">
19+
<ItemsRepeater.Layout>
20+
<StackLayout Orientation="Horizontal" />
21+
</ItemsRepeater.Layout>
22+
</ItemsRepeater>
23+
</ControlTemplate>
24+
</Setter.Value>
25+
</Setter>
26+
</Style>
27+
28+
<Style x:Key="DefaultBreadcrumbBarItemStyle" TargetType="local:BreadcrumbBarItem">
29+
<Setter Property="Background" Value="{ThemeResource BreadcrumbBarBackgroundBrush}" />
30+
<Setter Property="BorderBrush" Value="{ThemeResource BreadcrumbBarBorderBrush}" />
31+
<Setter Property="FontFamily" Value="{ThemeResource ContentControlThemeFontFamily}" />
32+
<Setter Property="FontSize" Value="{ThemeResource BreadcrumbBarItemThemeFontSize}" />
33+
<Setter Property="FontWeight" Value="{ThemeResource BreadcrumbBarItemFontWeight}" />
34+
<Setter Property="Foreground" Value="{ThemeResource BreadcrumbBarForegroundBrush}" />
35+
<Setter Property="Height" Value="{ThemeResource BreadcrumbBarItemHeight}" />
36+
<Setter Property="HorizontalAlignment" Value="Stretch" />
37+
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
38+
<Setter Property="IsTabStop" Value="True" />
39+
<Setter Property="UseSystemFocusVisuals" Value="{StaticResource UseSystemFocusVisuals}" />
40+
<Setter Property="VerticalAlignment" Value="Stretch" />
41+
<Setter Property="VerticalContentAlignment" Value="Stretch" />
42+
<Setter Property="CornerRadius" Value="2" />
43+
<Setter Property="Template">
44+
<Setter.Value>
45+
<ControlTemplate TargetType="local:BreadcrumbBarItem">
46+
<Grid x:Name="PART_LayoutRoot" ColumnSpacing="2">
47+
<Grid.ColumnDefinitions>
48+
<ColumnDefinition x:Name="PART_ContentColumn" Width="Auto" />
49+
<ColumnDefinition x:Name="PART_ChevronColumn" Width="Auto" />
50+
</Grid.ColumnDefinitions>
51+
52+
<!-- Clickable Area -->
53+
<Border
54+
x:Name="PART_ItemButton"
55+
Background="Transparent"
56+
CornerRadius="{TemplateBinding CornerRadius}">
57+
<Border.BackgroundTransition>
58+
<BrushTransition Duration="0:0:0.083" />
59+
</Border.BackgroundTransition>
60+
61+
<ContentPresenter
62+
x:Name="PART_ItemContentPresenter"
63+
Margin="8,0"
64+
HorizontalAlignment="Center"
65+
VerticalAlignment="Center"
66+
Content="{TemplateBinding Content}"
67+
ContentTemplate="{TemplateBinding ContentTemplate}" />
68+
69+
</Border>
70+
71+
<!-- Chevron -->
72+
<Border
73+
x:Name="PART_ChevronButton"
74+
Grid.Column="1"
75+
Background="Transparent"
76+
CornerRadius="{TemplateBinding CornerRadius}">
77+
<Border.BackgroundTransition>
78+
<BrushTransition Duration="0:0:0.083" />
79+
</Border.BackgroundTransition>
80+
<FlyoutBase.AttachedFlyout>
81+
<MenuFlyout Placement="Bottom">
82+
<MenuFlyout.MenuFlyoutPresenterStyle>
83+
<Style TargetType="MenuFlyoutPresenter">
84+
<Setter Property="MaxHeight" Value="400" />
85+
<!-- Workaround for https://github.com/files-community/Files/issues/13078 -->
86+
<Setter Target="HighContrastAdjustment" Value="None" />
87+
</Style>
88+
</MenuFlyout.MenuFlyoutPresenterStyle>
89+
</MenuFlyout>
90+
</FlyoutBase.AttachedFlyout>
91+
92+
<FontIcon
93+
x:Name="PART_ChevronTextBlock"
94+
Margin="4,0"
95+
HorizontalAlignment="Center"
96+
VerticalAlignment="Center"
97+
FontSize="12"
98+
Glyph="&#xE76C;" />
99+
100+
</Border>
101+
102+
<VisualStateManager.VisualStateGroups>
103+
104+
<VisualStateGroup x:Name="PointerStates">
105+
<VisualState x:Name="PointerNormal" />
106+
107+
<VisualState x:Name="PointerOverItem">
108+
<VisualState.Setters>
109+
<Setter Target="PART_ItemButton.Background" Value="{ThemeResource ControlFillColorSecondaryBrush}" />
110+
<Setter Target="PART_ChevronButton.Background" Value="{ThemeResource ControlFillColorSecondaryBrush}" />
111+
</VisualState.Setters>
112+
</VisualState>
113+
<VisualState x:Name="PointerOverChevron">
114+
<VisualState.Setters>
115+
<Setter Target="PART_ChevronButton.Background" Value="{ThemeResource ControlFillColorSecondaryBrush}" />
116+
</VisualState.Setters>
117+
</VisualState>
118+
119+
<VisualState x:Name="PointerPressedOnItem">
120+
<VisualState.Setters>
121+
<Setter Target="PART_ItemButton.Background" Value="{ThemeResource ControlFillColorTertiaryBrush}" />
122+
<Setter Target="PART_ChevronButton.Background" Value="{ThemeResource ControlFillColorTertiaryBrush}" />
123+
</VisualState.Setters>
124+
</VisualState>
125+
<VisualState x:Name="PointerPressedOnChevron">
126+
<VisualState.Setters>
127+
<Setter Target="PART_ChevronButton.Background" Value="{ThemeResource ControlFillColorTertiaryBrush}" />
128+
</VisualState.Setters>
129+
</VisualState>
130+
131+
</VisualStateGroup>
132+
133+
<VisualStateGroup x:Name="ItemTypeStates">
134+
<VisualState x:Name="DefaultItemType" />
135+
<VisualState x:Name="LastItemType">
136+
<VisualState.Setters>
137+
<Setter Target="PART_ItemButton.Visibility" Value="Collapsed" />
138+
</VisualState.Setters>
139+
</VisualState>
140+
<!--<VisualState x:Name="CollapsedItemType">
141+
<VisualState.Setters>
142+
</VisualState.Setters>
143+
</VisualState>-->
144+
</VisualStateGroup>
145+
146+
</VisualStateManager.VisualStateGroups>
147+
</Grid>
148+
</ControlTemplate>
149+
</Setter.Value>
150+
</Setter>
151+
</Style>
152+
153+
<Style x:Key="DefaultBreadcrumbEllipsisFlyoutStyle" TargetType="FlyoutPresenter">
154+
<Setter Property="Background" Value="{ThemeResource BreadcrumbBarEllipsisFlyoutPresenterBackground}" />
155+
<Setter Property="BorderBrush" Value="{ThemeResource BreadcrumbBarEllipsisFlyoutPresenterBorderBrush}" />
156+
<Setter Property="BorderThickness" Value="{ThemeResource BreadcrumbBarEllipsisFlyoutPresenterBorderThemeThickness}" />
157+
<Setter Property="Padding" Value="0,2" />
158+
<Setter Property="ScrollViewer.HorizontalScrollMode" Value="Disabled" />
159+
<Setter Property="ScrollViewer.VerticalScrollMode" Value="Auto" />
160+
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto" />
161+
<Setter Property="ScrollViewer.IsHorizontalRailEnabled" Value="False" />
162+
<Setter Property="ScrollViewer.IsVerticalRailEnabled" Value="False" />
163+
<Setter Property="ScrollViewer.ZoomMode" Value="Disabled" />
164+
<Setter Property="MaxWidth" Value="{ThemeResource FlyoutThemeMaxWidth}" />
165+
<Setter Property="MinHeight" Value="40" />
166+
<Setter Property="CornerRadius" Value="{ThemeResource OverlayCornerRadius}" />
167+
<Setter Property="Template">
168+
<Setter.Value>
169+
<ControlTemplate TargetType="FlyoutPresenter">
170+
<Grid
171+
Background="{TemplateBinding Background}"
172+
BackgroundSizing="InnerBorderEdge"
173+
CornerRadius="{TemplateBinding CornerRadius}">
174+
<ScrollViewer
175+
x:Name="FlyoutPresenterScrollViewer"
176+
Margin="{TemplateBinding Padding}"
177+
AutomationProperties.AccessibilityView="Raw"
178+
Content="{TemplateBinding Content}"
179+
HorizontalScrollBarVisibility="{TemplateBinding ScrollViewer.HorizontalScrollBarVisibility}"
180+
HorizontalScrollMode="{TemplateBinding ScrollViewer.HorizontalScrollMode}"
181+
IsHorizontalRailEnabled="{TemplateBinding ScrollViewer.IsHorizontalRailEnabled}"
182+
IsVerticalRailEnabled="{TemplateBinding ScrollViewer.IsVerticalRailEnabled}"
183+
VerticalScrollBarVisibility="{TemplateBinding ScrollViewer.VerticalScrollBarVisibility}"
184+
VerticalScrollMode="{TemplateBinding ScrollViewer.VerticalScrollMode}"
185+
ZoomMode="{TemplateBinding ScrollViewer.ZoomMode}" />
186+
<Border
187+
x:Name="FlyoutPresenterBorder"
188+
BorderBrush="{TemplateBinding BorderBrush}"
189+
BorderThickness="{TemplateBinding BorderThickness}"
190+
CornerRadius="{TemplateBinding CornerRadius}" />
191+
</Grid>
192+
</ControlTemplate>
193+
</Setter.Value>
194+
</Setter>
195+
</Style>
196+
197+
</ResourceDictionary>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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 sealed partial class BreadcrumbBarItem
16+
{
17+
[GeneratedDependencyProperty]
18+
public partial object? Children { get; set; }
19+
}
20+
}

0 commit comments

Comments
 (0)