First pass at navigation with MasterDetail

This commit is contained in:
watsonb8
2019-05-17 18:21:02 -04:00
parent 4f8b6f49fa
commit 62579677cf
333 changed files with 5505 additions and 31 deletions

View File

@ -0,0 +1,9 @@
<?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.Frontend.Views.Main.MainContentPage"
Title="Detail">
<StackLayout>
<Label Text="This is a detail page. To get the 'triple' line icon on each platform add a icon to each platform and update the 'Master' page with an Icon that references it." />
</StackLayout>
</ContentPage>

View File

@ -0,0 +1,14 @@
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
namespace Aurora.Frontend.Views.Main
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class MainContentPage : ContentPage
{
public MainContentPage()
{
InitializeComponent();
}
}
}

View File

@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:views="clr-namespace:Aurora.Frontend.Views.Main"
x:Class="Aurora.Frontend.Views.Main.MainView">
<ContentPage.Content>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="150" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<views:NavigationMenu Grid.Column="0"/>
</Grid>
</ContentPage.Content>
</ContentPage>-->
<MasterDetailPage
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:views="clr-namespace:Aurora.Frontend.Views.Main"
x:Class="Aurora.Frontend.Views.Main.MainView"
MasterBehavior="Split">
<MasterDetailPage.Master>
<views:NavigationMenu x:Name="MasterPage"/>
</MasterDetailPage.Master>
<MasterDetailPage.Detail>
<NavigationPage>
<x:Arguments>
<views:MainContentPage />
</x:Arguments>
</NavigationPage>
</MasterDetailPage.Detail>
</MasterDetailPage>

View File

@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
namespace Aurora.Frontend.Views.Main
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class MainView : MasterDetailPage
{
public MainView()
{
InitializeComponent();
MasterPage.ListView.ItemSelected += ListView_ItemSelected;
}
private void ListView_ItemSelected(object sender, SelectedItemChangedEventArgs e)
{
var item = e.SelectedItem as NavigationItem;
if (item == null)
return;
var page = (Page)Activator.CreateInstance(item.TargetType);
page.Title = item.Title;
Detail = new NavigationPage(page);
MasterPage.ListView.SelectedItem = null;
}
}
}

View File

@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Aurora.Frontend.Views.Main
{
public class NavigationItem
{
public NavigationItem()
{
TargetType = typeof(MainContentPage);
}
public int Id { get; set; }
public string Title { get; set; }
public Type TargetType { get; set; }
}
}

View File

@ -0,0 +1,41 @@
<?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.Frontend.Views.Main.NavigationMenu"
Title="asdf">
<StackLayout>
<ListView x:Name="MenuItemsListView"
SeparatorVisibility="None"
HasUnevenRows="true"
BackgroundColor="{StaticResource MenuBackgroundColor}"
CachingStrategy="RecycleElement"
ItemsSource="{Binding MenuItems}">
<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="AppName" Style="{DynamicResource SubtitleStyle}" />
</Grid>
</ListView.Header>
<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>
</ContentPage>

View File

@ -0,0 +1,56 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
namespace Aurora.Frontend.Views.Main
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class NavigationMenu : ContentPage
{
public ListView ListView;
public NavigationMenu()
{
InitializeComponent();
BindingContext = new MainViewMasterViewModel();
ListView = MenuItemsListView;
}
class MainViewMasterViewModel : INotifyPropertyChanged
{
public ObservableCollection<NavigationItem> MenuItems { get; set; }
public MainViewMasterViewModel()
{
MenuItems = new ObservableCollection<NavigationItem>(new[]
{
new NavigationItem { Id = 0, Title = "Page 1" },
new NavigationItem { Id = 1, Title = "Page 2" },
new NavigationItem { Id = 2, Title = "Page 3" },
new NavigationItem { Id = 3, Title = "Page 4" },
new NavigationItem { Id = 4, Title = "Page 5" },
});
}
#region INotifyPropertyChanged Implementation
public event PropertyChangedEventHandler PropertyChanged;
void OnPropertyChanged([CallerMemberName] string propertyName = "")
{
if (PropertyChanged == null)
return;
PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
#endregion
}
}
}