Skip to content

Commit d117eb5

Browse files
committed
Add SidebarView
1 parent 7250e87 commit d117eb5

16 files changed

+18143
-22248
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Copyright (c) Files Community
2+
// Licensed under the MIT License.
3+
4+
using System.ComponentModel;
5+
6+
namespace DevWinUI;
7+
8+
public interface ISidebarItemModel : INotifyPropertyChanged
9+
{
10+
/// <summary>
11+
/// The children of this item that will be rendered as child elements of the SidebarItem
12+
/// </summary>
13+
object? Children { get; }
14+
15+
/// <summary>
16+
/// The icon source used to generate the icon for the SidebarItem
17+
/// </summary>
18+
IconSource? IconSource { get; }
19+
20+
/// <summary>
21+
/// Item decorator for the given item.
22+
/// </summary>
23+
FrameworkElement? ItemDecorator { get => null; }
24+
25+
/// <summary>
26+
/// Determines whether the SidebarItem is expanded and the children are visible
27+
/// or if it is collapsed and children are not visible.
28+
/// </summary>
29+
bool IsExpanded { get; set; }
30+
31+
/// <summary>
32+
/// The text of this item that will be rendered as the label of the SidebarItem
33+
/// </summary>
34+
string Text { get; }
35+
36+
/// <summary>
37+
/// The tooltip used when hovering over this item in the sidebar
38+
/// </summary>
39+
object ToolTip { get; }
40+
41+
/// <summary>
42+
/// Indicates whether the children should have an indentation or not.
43+
/// </summary>
44+
bool PaddedItem { get; }
45+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Copyright (c) Files Community
2+
// Licensed under the MIT License.
3+
4+
using Microsoft.UI.Input;
5+
using Windows.ApplicationModel.DataTransfer;
6+
7+
namespace DevWinUI;
8+
9+
public record ItemInvokedEventArgs(PointerUpdateKind PointerUpdateKind) { }
10+
public record ItemDroppedEventArgs(object DropTarget, DataPackageView DroppedItem, SidebarItemDropPosition dropPosition, DragEventArgs RawEvent) { }
11+
public record ItemDragOverEventArgs(object DropTarget, DataPackageView DroppedItem, SidebarItemDropPosition dropPosition, DragEventArgs RawEvent) { }
12+
public record ItemContextInvokedArgs(object? Item, Point Position) { }
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright (c) Files Community
2+
// Licensed under the MIT License.
3+
4+
namespace DevWinUI;
5+
6+
/// <summary>
7+
/// The display mode of the <see cref="SidebarView"/>
8+
/// </summary>
9+
public enum SidebarDisplayMode
10+
{
11+
/// <summary>
12+
/// The sidebar is hidden and moves in from the side when the <see cref="SidebarView.IsPaneOpen"/> is set to <code>true</code>.
13+
/// </summary>
14+
Minimal,
15+
/// <summary>
16+
/// Only the icons of the top most sections are visible.
17+
/// </summary>
18+
Compact,
19+
/// <summary>
20+
/// The sidebar is expanded and items can also be expanded.
21+
/// </summary>
22+
Expanded
23+
}
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
// Copyright (c) Files Community
2+
// Licensed under the MIT License.
3+
4+
namespace DevWinUI;
5+
6+
public sealed partial class SidebarItem : Control
7+
{
8+
public SidebarView? Owner
9+
{
10+
get { return (SidebarView?)GetValue(OwnerProperty); }
11+
set { SetValue(OwnerProperty, value); }
12+
}
13+
public static readonly DependencyProperty OwnerProperty =
14+
DependencyProperty.Register(nameof(Owner), typeof(SidebarView), typeof(SidebarItem), new PropertyMetadata(null));
15+
16+
public bool IsSelected
17+
{
18+
get { return (bool)GetValue(IsSelectedProperty); }
19+
set { SetValue(IsSelectedProperty, value); }
20+
}
21+
public static readonly DependencyProperty IsSelectedProperty =
22+
DependencyProperty.Register(nameof(IsSelected), typeof(bool), typeof(SidebarItem), new PropertyMetadata(false, OnPropertyChanged));
23+
24+
public bool IsExpanded
25+
{
26+
get { return (bool)GetValue(IsExpandedProperty); }
27+
set { SetValue(IsExpandedProperty, value); }
28+
}
29+
public static readonly DependencyProperty IsExpandedProperty =
30+
DependencyProperty.Register(nameof(IsExpanded), typeof(bool), typeof(SidebarItem), new PropertyMetadata(true, OnPropertyChanged));
31+
32+
public bool IsInFlyout
33+
{
34+
get { return (bool)GetValue(IsInFlyoutProperty); }
35+
set { SetValue(IsInFlyoutProperty, value); }
36+
}
37+
public static readonly DependencyProperty IsInFlyoutProperty =
38+
DependencyProperty.Register(nameof(IsInFlyout), typeof(bool), typeof(SidebarItem), new PropertyMetadata(false));
39+
40+
public double ChildrenPresenterHeight
41+
{
42+
get { return (double)GetValue(ChildrenPresenterHeightProperty); }
43+
set { SetValue(ChildrenPresenterHeightProperty, value); }
44+
}
45+
// Using 30 as a default in case something goes wrong
46+
public static readonly DependencyProperty ChildrenPresenterHeightProperty =
47+
DependencyProperty.Register(nameof(ChildrenPresenterHeight), typeof(double), typeof(SidebarItem), new PropertyMetadata(30d));
48+
49+
public ISidebarItemModel? Item
50+
{
51+
get { return (ISidebarItemModel)GetValue(ItemProperty); }
52+
set { SetValue(ItemProperty, value); }
53+
}
54+
public static readonly DependencyProperty ItemProperty =
55+
DependencyProperty.Register(nameof(Item), typeof(ISidebarItemModel), typeof(SidebarItem), new PropertyMetadata(null));
56+
57+
public bool UseReorderDrop
58+
{
59+
get { return (bool)GetValue(UseReorderDropProperty); }
60+
set { SetValue(UseReorderDropProperty, value); }
61+
}
62+
public static readonly DependencyProperty UseReorderDropProperty =
63+
DependencyProperty.Register(nameof(UseReorderDrop), typeof(bool), typeof(SidebarItem), new PropertyMetadata(false));
64+
65+
public FrameworkElement? Icon
66+
{
67+
get { return (FrameworkElement?)GetValue(IconProperty); }
68+
set { SetValue(IconProperty, value); }
69+
}
70+
public static readonly DependencyProperty IconProperty =
71+
DependencyProperty.Register(nameof(Icon), typeof(FrameworkElement), typeof(SidebarItem), new PropertyMetadata(null));
72+
73+
public FrameworkElement? Decorator
74+
{
75+
get { return (FrameworkElement?)GetValue(DecoratorProperty); }
76+
set { SetValue(DecoratorProperty, value); }
77+
}
78+
public static readonly DependencyProperty DecoratorProperty =
79+
DependencyProperty.Register(nameof(Decorator), typeof(FrameworkElement), typeof(SidebarItem), new PropertyMetadata(null));
80+
81+
public SidebarDisplayMode DisplayMode
82+
{
83+
get { return (SidebarDisplayMode)GetValue(DisplayModeProperty); }
84+
set { SetValue(DisplayModeProperty, value); }
85+
}
86+
public static readonly DependencyProperty DisplayModeProperty =
87+
DependencyProperty.Register(nameof(DisplayMode), typeof(SidebarDisplayMode), typeof(SidebarItem), new PropertyMetadata(SidebarDisplayMode.Expanded, OnPropertyChanged));
88+
89+
public static void SetTemplateRoot(DependencyObject target, FrameworkElement value)
90+
{
91+
target.SetValue(TemplateRootProperty, value);
92+
}
93+
public static FrameworkElement GetTemplateRoot(DependencyObject target)
94+
{
95+
return (FrameworkElement)target.GetValue(TemplateRootProperty);
96+
}
97+
public static readonly DependencyProperty TemplateRootProperty =
98+
DependencyProperty.Register("TemplateRoot", typeof(FrameworkElement), typeof(FrameworkElement), new PropertyMetadata(null));
99+
100+
public static void OnPropertyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
101+
{
102+
if (sender is not SidebarItem item) return;
103+
if (e.Property == DisplayModeProperty)
104+
{
105+
item.SidebarDisplayModeChanged((SidebarDisplayMode)e.OldValue);
106+
}
107+
else if (e.Property == IsSelectedProperty)
108+
{
109+
item.UpdateSelectionState();
110+
}
111+
else if (e.Property == IsExpandedProperty)
112+
{
113+
item.UpdateExpansionState();
114+
}
115+
else if (e.Property == ItemProperty)
116+
{
117+
item.HandleItemChange();
118+
}
119+
}
120+
}

0 commit comments

Comments
 (0)