Reorganization
This commit is contained in:
@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
namespace Aurora.Design.Components.NavigationMenu
|
||||
{
|
||||
public class NavigationGroupItem : List<NavigationItem>
|
||||
{
|
||||
public NavigationGroupItem()
|
||||
{
|
||||
}
|
||||
|
||||
public NavigationGroupItem(string heading)
|
||||
{
|
||||
GroupHeading = heading;
|
||||
}
|
||||
|
||||
public List<NavigationItem> Items => this;
|
||||
public string GroupHeading { get; set; }
|
||||
}
|
||||
}
|
21
Aurora/Design/Components/NavigationMenu/NavigationItem.cs
Normal file
21
Aurora/Design/Components/NavigationMenu/NavigationItem.cs
Normal file
@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Aurora.Design.Views.Main;
|
||||
|
||||
namespace Aurora.Design.Components.NavigationMenu
|
||||
{
|
||||
public class NavigationItem
|
||||
{
|
||||
public NavigationItem()
|
||||
{
|
||||
}
|
||||
public int Id { get; set; }
|
||||
public string Title { get; set; }
|
||||
public string Group { get; set; }
|
||||
|
||||
public Type TargetType { get; set; }
|
||||
}
|
||||
}
|
74
Aurora/Design/Components/NavigationMenu/NavigationMenu.xaml
Normal file
74
Aurora/Design/Components/NavigationMenu/NavigationMenu.xaml
Normal file
@ -0,0 +1,74 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ContentPage
|
||||
xmlns="http://xamarin.com/schemas/2014/forms"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
x:Class="Aurora.Design.Components.NavigationMenu.NavigationMenu"
|
||||
Title="Navigation">
|
||||
<ContentView.Content>
|
||||
<StackLayout>
|
||||
<ListView
|
||||
x:Name="MenuItemsListView"
|
||||
SeparatorVisibility="None"
|
||||
HasUnevenRows="true"
|
||||
BackgroundColor="{StaticResource MenuBackgroundColor}"
|
||||
IsGroupingEnabled="true"
|
||||
CachingStrategy="RecycleElement">
|
||||
<ListView.Header>
|
||||
<Grid
|
||||
BackgroundColor="#03A9F4">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition
|
||||
Width="10"/>
|
||||
<ColumnDefinition
|
||||
Width="*"/>
|
||||
<ColumnDefinition
|
||||
Width="10"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition
|
||||
Height="30"/>
|
||||
<RowDefinition
|
||||
Height="80"/>
|
||||
<RowDefinition
|
||||
Height="Auto"/>
|
||||
<RowDefinition
|
||||
Height="10"/>
|
||||
</Grid.RowDefinitions>
|
||||
<Label
|
||||
Grid.Column="1"
|
||||
Grid.Row="2"
|
||||
Text="Aurora"
|
||||
Style="{DynamicResource SubtitleStyle}"/>
|
||||
</Grid>
|
||||
</ListView.Header>
|
||||
<ListView.GroupHeaderTemplate>
|
||||
<DataTemplate>
|
||||
<ViewCell>
|
||||
<Label
|
||||
VerticalOptions="FillAndExpand"
|
||||
VerticalTextAlignment="Start"
|
||||
Text="{Binding GroupHeading}"
|
||||
FontSize="18"
|
||||
TextColor="White"/>
|
||||
</ViewCell>
|
||||
</DataTemplate>
|
||||
</ListView.GroupHeaderTemplate>
|
||||
<ListView.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<ViewCell>
|
||||
<StackLayout
|
||||
Padding="15,10"
|
||||
HorizontalOptions="FillAndExpand">
|
||||
<Label
|
||||
VerticalOptions="FillAndExpand"
|
||||
VerticalTextAlignment="Center"
|
||||
Text="{Binding Title}"
|
||||
FontSize="24"/>
|
||||
</StackLayout>
|
||||
</ViewCell>
|
||||
</DataTemplate>
|
||||
</ListView.ItemTemplate>
|
||||
</ListView>
|
||||
</StackLayout>
|
||||
</ContentView.Content>
|
||||
</ContentPage>
|
@ -0,0 +1,77 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using Xamarin.Forms;
|
||||
|
||||
namespace Aurora.Design.Components.NavigationMenu
|
||||
{
|
||||
public partial class NavigationMenu : ContentPage
|
||||
{
|
||||
public NavigationMenu()
|
||||
{
|
||||
InitializeComponent();
|
||||
ListView = MenuItemsListView;
|
||||
}
|
||||
|
||||
public ListView ListView;
|
||||
|
||||
public static readonly BindableProperty ItemsProperty =
|
||||
BindableProperty.Create(propertyName: nameof(Items),
|
||||
returnType: typeof(ObservableCollection<NavigationItem>),
|
||||
declaringType: typeof(NavigationMenu),
|
||||
defaultBindingMode: BindingMode.TwoWay,
|
||||
propertyChanged: OnItemsChanged);
|
||||
|
||||
public ObservableCollection<NavigationItem> Items
|
||||
{
|
||||
get
|
||||
{
|
||||
return (ObservableCollection<NavigationItem>)GetValue(ItemsProperty);
|
||||
}
|
||||
set
|
||||
{
|
||||
SetValue(ItemsProperty, value);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Items changed event handler. Organizes items in groups for display.
|
||||
/// </summary>
|
||||
/// <param name="bindable">The changed Item.</param>
|
||||
/// <param name="oldValue">The previous value.</param>
|
||||
/// <param name="newValue">The new value.</param>
|
||||
private static void OnItemsChanged(BindableObject bindable, object oldValue, object newValue)
|
||||
{
|
||||
var control = (NavigationMenu)bindable;
|
||||
ObservableCollection<NavigationItem> items = (ObservableCollection<NavigationItem>)newValue;
|
||||
Dictionary<string, NavigationGroupItem> groupDictioanry = new Dictionary<string, NavigationGroupItem>();
|
||||
|
||||
//Populate dictionary where group heading is the key
|
||||
foreach (NavigationItem item in items)
|
||||
{
|
||||
if (groupDictioanry.ContainsKey(item.Group))
|
||||
{
|
||||
groupDictioanry.TryGetValue(item.Group, out var groupItem);
|
||||
groupItem.Items.Add(item);
|
||||
}
|
||||
else
|
||||
{
|
||||
NavigationGroupItem groupItem = new NavigationGroupItem(item.Group);
|
||||
groupItem.Add(item);
|
||||
|
||||
groupDictioanry.Add(item.Group, groupItem);
|
||||
}
|
||||
}
|
||||
|
||||
ObservableCollection<NavigationGroupItem> groups = new ObservableCollection<NavigationGroupItem>();
|
||||
foreach (string groupHeading in groupDictioanry.Keys)
|
||||
{
|
||||
groupDictioanry.TryGetValue(groupHeading, out var groupItem);
|
||||
groups.Add(groupItem);
|
||||
}
|
||||
|
||||
control.MenuItemsListView.ItemsSource = groups;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user