Migrate aurora-sharp-desktop
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; }
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
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; }
|
||||
public Type TargetViewModelType { get; set; }
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
ListView {
|
||||
margin-left: 15;
|
||||
margin-top: 40;
|
||||
}
|
||||
|
||||
#GroupTemplate {
|
||||
align-items: end;
|
||||
}
|
||||
|
||||
#GroupCell Label {
|
||||
color: lightgray;
|
||||
font-size: 12;
|
||||
font-family: Courier New, Courier, monospace;
|
||||
font-style: italic;
|
||||
padding-top: 20;
|
||||
}
|
||||
|
||||
#ItemCell Label {
|
||||
color: white;
|
||||
font-size: 15;
|
||||
font-family: Courier New, Courier, monospace;
|
||||
font-style: normal;
|
||||
text-align: left;
|
||||
padding-top: 12;
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ContentView
|
||||
xmlns="http://xamarin.com/schemas/2014/forms"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
x:Class="Aurora.Design.Components.NavigationMenu.NavigationMenu">
|
||||
<ContentView.Resources>
|
||||
<StyleSheet
|
||||
Source="NavigationMenu.css"/>
|
||||
</ContentView.Resources>
|
||||
<ContentView.Content>
|
||||
<StackLayout
|
||||
x:Name="Layout"
|
||||
StyleClass="primaryColor">
|
||||
<ListView
|
||||
x:Name="MenuItemsListView"
|
||||
HasUnevenRows="true"
|
||||
SeparatorVisibility="None"
|
||||
IsGroupingEnabled="true"
|
||||
RowHeight="35"
|
||||
StyleClass="primaryColor"
|
||||
CachingStrategy="RecycleElement">
|
||||
<ListView.GroupHeaderTemplate>
|
||||
<DataTemplate>
|
||||
<ViewCell
|
||||
x:Name="GroupCell">
|
||||
<Label
|
||||
VerticalTextAlignment="Center"
|
||||
Text="{Binding GroupHeading}"/>
|
||||
</ViewCell>
|
||||
</DataTemplate>
|
||||
</ListView.GroupHeaderTemplate>
|
||||
<ListView.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<ViewCell
|
||||
x:Name="ItemCell">
|
||||
<Label
|
||||
StyleClass="primaryColor"
|
||||
Text="{Binding Title}"/>
|
||||
</ViewCell>
|
||||
</DataTemplate>
|
||||
</ListView.ItemTemplate>
|
||||
</ListView>
|
||||
</StackLayout>
|
||||
</ContentView.Content>
|
||||
</ContentView>
|
@ -0,0 +1,102 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using Xamarin.Forms;
|
||||
|
||||
namespace Aurora.Design.Components.NavigationMenu
|
||||
{
|
||||
public partial class NavigationMenu : ContentView
|
||||
{
|
||||
public NavigationMenu()
|
||||
{
|
||||
InitializeComponent();
|
||||
ListView = MenuItemsListView;
|
||||
ListView.ItemSelected += ListView_ItemSelected;
|
||||
}
|
||||
|
||||
private void ListView_ItemSelected(object sender, SelectedItemChangedEventArgs e)
|
||||
{
|
||||
this.SelectedItem = e.SelectedItem as NavigationItem;
|
||||
}
|
||||
|
||||
public ListView ListView;
|
||||
|
||||
public static readonly BindableProperty SelectedItemProperty =
|
||||
BindableProperty.Create(propertyName: nameof(SelectedItem),
|
||||
returnType: typeof(NavigationItem),
|
||||
declaringType: typeof(NavigationMenu),
|
||||
defaultBindingMode: BindingMode.OneWayToSource);
|
||||
|
||||
public NavigationItem SelectedItem
|
||||
{
|
||||
get
|
||||
{
|
||||
return (NavigationItem)GetValue(SelectedItemProperty);
|
||||
}
|
||||
set
|
||||
{
|
||||
SetValue(SelectedItemProperty, value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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