1
0
Fork 0
mirror of https://github.com/Nioux/AideDeJeu.git synced 2025-10-30 06:56:10 +00:00

Séparation ItemsPage / FilteredItemsPage

This commit is contained in:
Yan Maniez 2018-07-22 16:29:39 +02:00
parent 73a3cc5982
commit f8e5423d8f
7 changed files with 184 additions and 94 deletions

View file

@ -39,6 +39,9 @@
<Compile Update="Views\ItemDetailPage.xaml.cs">
<DependentUpon>ItemDetailPage.xaml</DependentUpon>
</Compile>
<Compile Update="Views\FilteredItemsPage.xaml.cs">
<DependentUpon>FilteredItemsPage.xaml</DependentUpon>
</Compile>
<Compile Update="Views\ItemsPage.xaml.cs">
<DependentUpon>ItemsPage.xaml</DependentUpon>
</Compile>

View file

@ -81,7 +81,14 @@ namespace AideDeJeu.ViewModels
{
var itemsViewModel = new ItemsViewModel() { AllItems = items };
itemsViewModel.LoadItemsCommand.Execute(null);
await Navigator.GotoItemsPageAsync(itemsViewModel);
if (items.GetNewFilterViewModel() == null)
{
await Navigator.GotoItemsPageAsync(itemsViewModel);
}
else
{
await Navigator.GotoFilteredItemsPageAsync(itemsViewModel);
}
}
}
else

View file

@ -42,5 +42,13 @@ namespace AideDeJeu.ViewModels
await Navigation.PushAsync(new ItemsPage(itemsVM));
}
public async Task GotoFilteredItemsPageAsync(ItemsViewModel itemsVM)
{
if (itemsVM == null)
return;
await Navigation.PushAsync(new FilteredItemsPage(itemsVM));
}
}
}

View file

@ -0,0 +1,70 @@
<?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:local="clr-namespace:AideDeJeu.Views"
xmlns:tools="clr-namespace:AideDeJeu.Tools"
x:Class="AideDeJeu.Views.FilteredItemsPage"
x:Name="This"
IsPresented="False"
Title="{Binding Title}">
<MasterDetailPage.ToolbarItems>
<ToolbarItem Name="About" Text="À propos de..." Order="Secondary" Icon="wooden_sign.png" Command="{Binding Main.AboutCommand}" />
</MasterDetailPage.ToolbarItems>
<MasterDetailPage.Resources>
<ResourceDictionary>
</ResourceDictionary>
</MasterDetailPage.Resources>
<MasterDetailPage.Master>
<ContentPage Title=" ">
<StackLayout Orientation="Vertical">
<ListView SelectionMode="None" ItemsSource="{Binding Filter.Filters}" HasUnevenRows="True" RowHeight="-1" SeparatorVisibility="None" IsPullToRefreshEnabled="False" HorizontalOptions="FillAndExpand" >
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<ViewCell.View>
<StackLayout Margin="10,5,10,0" Padding="0" Spacing="0">
<Label BindingContext="{Binding}" Text="{Binding Name}" Style="{StaticResource Key=subsubsection}" />
<Picker HorizontalOptions="FillAndExpand" ItemsSource="{Binding KeyValues, Mode=OneWay}" ItemDisplayBinding="{Binding Value, Mode=OneWay}" SelectedIndex="{Binding Index}" />
</StackLayout>
</ViewCell.View>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
</ContentPage>
</MasterDetailPage.Master>
<MasterDetailPage.Detail>
<ContentPage Title="">
<Grid VerticalOptions="Fill" HorizontalOptions="Fill">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Button Grid.Column="0" Grid.Row="0" Text="=" Clicked="Button_Clicked"/>
<SearchBar Grid.Column="1" Grid.Row="0" x:Name="SearchBar" HeightRequest="42" SearchCommand="{Binding SearchCommand}" SearchCommandParameter="{Binding Text, Source={x:Reference SearchBar}}">
<SearchBar.Behaviors>
<tools:TextChangedBehavior />
</SearchBar.Behaviors>
</SearchBar>
<ListView Grid.Column="0" Grid.Row="1" Grid.ColumnSpan="2" x:Name="ItemsListView" ItemsSource="{Binding Items}" VerticalOptions="FillAndExpand" HasUnevenRows="true" CachingStrategy="RecycleElement" SelectedItem="{Binding SelectedItem}" ItemTapped="ItemsListView_ItemTapped">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell AutomationProperties.IsInAccessibleTree="True" AutomationId="machin" AutomationProperties.Name="hop">
<StackLayout Padding="10" Orientation="Vertical">
<Label Text="{Binding Name}" LineBreakMode="NoWrap" Style="{DynamicResource subsubsection}" FontSize="16" />
<Label Text="{Binding AltNameText}" LineBreakMode="NoWrap" Style="{DynamicResource subsubsection}" FontSize="12" />
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Grid>
</ContentPage>
</MasterDetailPage.Detail>
</MasterDetailPage>

View file

@ -0,0 +1,77 @@
using AideDeJeu.ViewModels;
using System;
using System.Linq;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
namespace AideDeJeu.Views
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class FilteredItemsPage : MasterDetailPage
{
MainViewModel Main
{
get
{
return DependencyService.Get<MainViewModel>();
}
}
//INavig//ator Navigator;
public ItemsViewModel _ItemsViewModel;
public ItemsViewModel ItemsViewModel
{
get
{
return _ItemsViewModel;
}
}
public FilteredItemsPage (ItemsViewModel itemsViewModel)
{
InitializeComponent ();
BindingContext = _ItemsViewModel = itemsViewModel; // Main;
//this.SizeChanged += (o, e) => {
// if(this.Width > 0 && this.Height > 0)
// {
// this.IsPresented = this.Width > this.Height;
// }
//};
}
public FilteredItemsPage()
{
InitializeComponent();
BindingContext = Main;
//this.SizeChanged += (o, e) => {
// if (this.Width > 0 && this.Height > 0)
// {
// this.IsPresented = this.Width > this.Height;
// }
//};
}
protected override void OnAppearing()
{
base.OnAppearing();
this.MasterBehavior = MasterBehavior.Popover;
//if (Main.Items.Count() == 0)
//Main.LoadItemsCommand.Execute(null);
}
private void ItemsListView_ItemTapped(object sender, ItemTappedEventArgs e)
{
if (e.Item == null) return;
((ListView)sender).SelectedItem = null;
}
private void Button_Clicked(object sender, EventArgs e)
{
this.IsPresented = !this.IsPresented;
}
}
}

View file

@ -1,70 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<MasterDetailPage
<ContentPage
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:AideDeJeu.Views"
xmlns:tools="clr-namespace:AideDeJeu.Tools"
x:Class="AideDeJeu.Views.ItemsPage"
x:Name="This"
IsPresented="False"
Title="{Binding Title}">
<MasterDetailPage.ToolbarItems>
<ContentPage.ToolbarItems>
<ToolbarItem Name="About" Text="À propos de..." Order="Secondary" Icon="wooden_sign.png" Command="{Binding Main.AboutCommand}" />
</MasterDetailPage.ToolbarItems>
<MasterDetailPage.Resources>
<ResourceDictionary>
</ResourceDictionary>
</MasterDetailPage.Resources>
<MasterDetailPage.Master>
<ContentPage Title=" ">
<StackLayout Orientation="Vertical">
<ListView SelectionMode="None" ItemsSource="{Binding Filter.Filters}" HasUnevenRows="True" RowHeight="-1" SeparatorVisibility="None" IsPullToRefreshEnabled="False" HorizontalOptions="FillAndExpand" >
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<ViewCell.View>
<StackLayout Margin="10,5,10,0" Padding="0" Spacing="0">
<Label BindingContext="{Binding}" Text="{Binding Name}" Style="{StaticResource Key=subsubsection}" />
<Picker HorizontalOptions="FillAndExpand" ItemsSource="{Binding KeyValues, Mode=OneWay}" ItemDisplayBinding="{Binding Value, Mode=OneWay}" SelectedIndex="{Binding Index}" />
</StackLayout>
</ViewCell.View>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
</ContentPage>
</MasterDetailPage.Master>
<MasterDetailPage.Detail>
<ContentPage Title="">
<Grid VerticalOptions="Fill" HorizontalOptions="Fill">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Button Grid.Column="0" Grid.Row="0" Text="=" Clicked="Button_Clicked"/>
<SearchBar Grid.Column="1" Grid.Row="0" x:Name="SearchBar" HeightRequest="42" SearchCommand="{Binding SearchCommand}" SearchCommandParameter="{Binding Text, Source={x:Reference SearchBar}}">
<SearchBar.Behaviors>
<tools:TextChangedBehavior />
</SearchBar.Behaviors>
</SearchBar>
<ListView Grid.Column="0" Grid.Row="1" Grid.ColumnSpan="2" x:Name="ItemsListView" ItemsSource="{Binding Items}" VerticalOptions="FillAndExpand" HasUnevenRows="true" CachingStrategy="RecycleElement" SelectedItem="{Binding SelectedItem}" ItemTapped="ItemsListView_ItemTapped">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell AutomationProperties.IsInAccessibleTree="True" AutomationId="machin" AutomationProperties.Name="hop">
<StackLayout Padding="10" Orientation="Vertical">
<Label Text="{Binding Name}" LineBreakMode="NoWrap" Style="{DynamicResource subsubsection}" FontSize="16" />
<Label Text="{Binding AltNameText}" LineBreakMode="NoWrap" Style="{DynamicResource subsubsection}" FontSize="12" />
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Grid>
</ContentPage>
</MasterDetailPage.Detail>
</MasterDetailPage>
</ContentPage.ToolbarItems>
<ListView HorizontalOptions="Fill" x:Name="ItemsListView" ItemsSource="{Binding Items}" VerticalOptions="FillAndExpand" HasUnevenRows="true" CachingStrategy="RecycleElement" SelectedItem="{Binding SelectedItem}" ItemTapped="ItemsListView_ItemTapped">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell AutomationProperties.IsInAccessibleTree="True" AutomationId="machin" AutomationProperties.Name="hop">
<StackLayout Padding="10" Orientation="Vertical">
<Label Text="{Binding Name}" LineBreakMode="NoWrap" Style="{DynamicResource subsubsection}" FontSize="16" />
<Label Text="{Binding AltNameText}" LineBreakMode="NoWrap" Style="{DynamicResource subsubsection}" FontSize="12" />
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</ContentPage>

View file

@ -7,7 +7,7 @@ using Xamarin.Forms.Xaml;
namespace AideDeJeu.Views
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class ItemsPage : MasterDetailPage
public partial class ItemsPage : ContentPage
{
MainViewModel Main
{
@ -16,7 +16,6 @@ namespace AideDeJeu.Views
return DependencyService.Get<MainViewModel>();
}
}
//INavig//ator Navigator;
public ItemsViewModel _ItemsViewModel;
public ItemsViewModel ItemsViewModel
@ -30,37 +29,13 @@ namespace AideDeJeu.Views
{
InitializeComponent ();
BindingContext = _ItemsViewModel = itemsViewModel; // Main;
//this.SizeChanged += (o, e) => {
// if(this.Width > 0 && this.Height > 0)
// {
// this.IsPresented = this.Width > this.Height;
// }
//};
BindingContext = _ItemsViewModel = itemsViewModel;
}
public ItemsPage()
{
InitializeComponent();
BindingContext = Main;
//this.SizeChanged += (o, e) => {
// if (this.Width > 0 && this.Height > 0)
// {
// this.IsPresented = this.Width > this.Height;
// }
//};
}
protected override void OnAppearing()
{
base.OnAppearing();
this.MasterBehavior = MasterBehavior.Popover;
//if (Main.Items.Count() == 0)
//Main.LoadItemsCommand.Execute(null);
}
private void ItemsListView_ItemTapped(object sender, ItemTappedEventArgs e)
@ -68,10 +43,5 @@ namespace AideDeJeu.Views
if (e.Item == null) return;
((ListView)sender).SelectedItem = null;
}
private void Button_Clicked(object sender, EventArgs e)
{
this.IsPresented = !this.IsPresented;
}
}
}