This commit is contained in:
ShaneN 2019-08-14 12:29:21 -06:00
Родитель 15e2e222e5
Коммит e530f74315
7 изменённых файлов: 226 добавлений и 8 удалений

Просмотреть файл

@ -6,14 +6,21 @@ using Xamarin.Forms.StyleSheets;
namespace Xamarin.Forms.Sandbox
{
public partial class App
{
void InitializeMainPage()
{
if(Device.RuntimePlatform == Device.UWP)
public partial class App
{
void InitializeMainPage()
{
bool useTabPage = false;
bool useMDP = false;
if (useMDP)
MainPage = new MDP();
else if (useTabPage)
MainPage = new TabPage();
else if (Device.RuntimePlatform == Device.UWP)
MainPage = new MainPage();
else
MainPage = new ShellPage();
}
}
MainPage = new ShellPage();
}
}
}

Просмотреть файл

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8" ?>
<MasterDetailPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
x:Class="Xamarin.Forms.Sandbox.MDP"
xmlns:local="clr-namespace:Xamarin.Forms.Sandbox">
<MasterDetailPage.Master>
<local:MDPMaster x:Name="MasterPage" />
</MasterDetailPage.Master>
<MasterDetailPage.Detail>
<NavigationPage>
<x:Arguments>
<local:MainPage />
</x:Arguments>
</NavigationPage>
</MasterDetailPage.Detail>
</MasterDetailPage>

Просмотреть файл

@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
namespace Xamarin.Forms.Sandbox
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class MDP : MasterDetailPage
{
public MDP()
{
InitializeComponent();
MasterPage.ListView.ItemSelected += ListView_ItemSelected;
}
private void ListView_ItemSelected(object sender, SelectedItemChangedEventArgs e)
{
var item = e.SelectedItem as MDPMasterMenuItem;
if (item == null)
return;
var page = (Page)Activator.CreateInstance(item.TargetType);
page.Title = item.Title;
Detail = new NavigationPage(page);
IsPresented = false;
MasterPage.ListView.SelectedItem = null;
}
}
}

Просмотреть файл

@ -0,0 +1,58 @@
<?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:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
x:Class="Xamarin.Forms.Sandbox.MDPMaster"
Title="Master">
<StackLayout>
<ListView x:Name="MenuItemsListView"
SeparatorVisibility="None"
HasUnevenRows="true"
ItemsSource="{Binding MenuItems}">
<d:ListView.ItemsSource>
<x:Array Type="{x:Type x:String}">
<x:String>Page 1</x:String>
<x:String>Page 2</x:String>
<x:String>Page 3</x:String>
<x:String>Page 4</x:String>
<x:String>Page 5</x:String>
</x:Array>
</d:ListView.ItemsSource>
<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}"
d:Text="{Binding .}"
FontSize="24"/>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
</ContentPage>

Просмотреть файл

@ -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 Xamarin.Forms.Sandbox
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class MDPMaster : ContentPage
{
public ListView ListView;
public MDPMaster()
{
InitializeComponent();
BindingContext = new MDPMasterViewModel();
ListView = MenuItemsListView;
}
class MDPMasterViewModel : INotifyPropertyChanged
{
public ObservableCollection<MDPMasterMenuItem> MenuItems { get; set; }
public MDPMasterViewModel()
{
MenuItems = new ObservableCollection<MDPMasterMenuItem>(new[]
{
new MDPMasterMenuItem { Id = 0, Title = "Page 1" },
new MDPMasterMenuItem { Id = 1, Title = "Page 2" },
new MDPMasterMenuItem { Id = 2, Title = "Page 3" },
new MDPMasterMenuItem { Id = 3, Title = "Page 4" },
new MDPMasterMenuItem { 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
}
}
}

Просмотреть файл

@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Xamarin.Forms.Sandbox
{
public class MDPMasterMenuItem
{
public MDPMasterMenuItem()
{
TargetType = typeof(MDPMasterMenuItem);
}
public int Id { get; set; }
public string Title { get; set; }
public Type TargetType { get; set; }
}
}

Просмотреть файл

@ -38,4 +38,25 @@
<Generator>MSBuild:Compile</Generator>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="MDP.xaml">
<Generator>MSBuild:Compile</Generator>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="MDPMaster.xaml">
<Generator>MSBuild:Compile</Generator>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="MDPDetail.xaml">
<Generator>MSBuild:Compile</Generator>
</EmbeddedResource>
</ItemGroup>
</Project>