mirror of
				https://github.com/Nioux/AideDeJeu.git
				synced 2025-10-31 15:36:07 +00:00 
			
		
		
		
	Passage en binding du selected item + nettoyage de code
This commit is contained in:
		
							parent
							
								
									07e3b708fa
								
							
						
					
					
						commit
						da08a4d387
					
				
					 3 changed files with 29 additions and 95 deletions
				
			
		|  | @ -48,6 +48,20 @@ namespace AideDeJeu.ViewModels | ||||||
|         } |         } | ||||||
|         public ObservableCollection<Item> Items { get; private set; } = new ObservableCollection<Item>(); |         public ObservableCollection<Item> Items { get; private set; } = new ObservableCollection<Item>(); | ||||||
| 
 | 
 | ||||||
|  |         private Item _SelectedItem; | ||||||
|  |         public Item SelectedItem | ||||||
|  |         { | ||||||
|  |             get | ||||||
|  |             { | ||||||
|  |                 return _SelectedItem; | ||||||
|  |             } | ||||||
|  |             set | ||||||
|  |             { | ||||||
|  |                 SetProperty(ref _SelectedItem, value); | ||||||
|  |                 GotoItemCommand.Execute(_SelectedItem); | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|         public Command LoadItemsCommand { get; private set; } |         public Command LoadItemsCommand { get; private set; } | ||||||
|         public Command<Item> GotoItemCommand { get; private set; } |         public Command<Item> GotoItemCommand { get; private set; } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -6,8 +6,7 @@ | ||||||
|                 x:Class="AideDeJeu.Views.MainPage" |                 x:Class="AideDeJeu.Views.MainPage" | ||||||
|                 x:Name="This" |                 x:Name="This" | ||||||
|                 IsPresented="False" |                 IsPresented="False" | ||||||
|                   Title="{Binding ItemsType,Converter={StaticResource ItemTypeToStringConverter}}" |                 Title="{Binding ItemsType,Converter={StaticResource ItemTypeToStringConverter}}"> | ||||||
|                 > |  | ||||||
|     <MasterDetailPage.Resources> |     <MasterDetailPage.Resources> | ||||||
|         <ResourceDictionary> |         <ResourceDictionary> | ||||||
|             <ControlTemplate x:Key="SpellsMasterDataTemplate"> |             <ControlTemplate x:Key="SpellsMasterDataTemplate"> | ||||||
|  | @ -80,7 +79,6 @@ | ||||||
|     <MasterDetailPage.Master> |     <MasterDetailPage.Master> | ||||||
|         <ContentPage Title=" "> |         <ContentPage Title=" "> | ||||||
|             <ContentView ControlTemplate="{Binding ItemsType, Converter={StaticResource ItemsTypeTemplateConverter}}" BindingContext="{Binding}" /> |             <ContentView ControlTemplate="{Binding ItemsType, Converter={StaticResource ItemsTypeTemplateConverter}}" BindingContext="{Binding}" /> | ||||||
|             <!--<ContentView ControlTemplate="{StaticResource SpellsMasterDataTemplate}" BindingContext="{Binding}" />--> |  | ||||||
|         </ContentPage> |         </ContentPage> | ||||||
|     </MasterDetailPage.Master> |     </MasterDetailPage.Master> | ||||||
|     <MasterDetailPage.Detail> |     <MasterDetailPage.Detail> | ||||||
|  | @ -89,20 +87,6 @@ | ||||||
|                 <ToolbarItem Name="Spells" Text="Sorts" Order="Primary" Icon="spell_book.png" Command="{Binding SwitchToSpells}" /> |                 <ToolbarItem Name="Spells" Text="Sorts" Order="Primary" Icon="spell_book.png" Command="{Binding SwitchToSpells}" /> | ||||||
|                 <ToolbarItem Name="Monsters" Text="Monstres" Order="Primary" Icon="dragon_head.png" Command="{Binding SwitchToMonsters}" /> |                 <ToolbarItem Name="Monsters" Text="Monstres" Order="Primary" Icon="dragon_head.png" Command="{Binding SwitchToMonsters}" /> | ||||||
|                 <ToolbarItem Name="About" Text="À propos de..." Order="Primary" Icon="wooden_sign.png" Command="{Binding AboutCommand}" /> |                 <ToolbarItem Name="About" Text="À propos de..." Order="Primary" Icon="wooden_sign.png" Command="{Binding AboutCommand}" /> | ||||||
|                 <!--<ToolbarItem Name="Home" Text="Accueil" Order="Primary" Icon="ic_home.png" Command="{Binding OpenUrl}" CommandParameter="http://www.pathfinder-fr.org/" /> |  | ||||||
|                 <ToolbarItem Name="Spells" Text="Sorts" Order="Primary" Icon="ic_home.png" Command="{Binding OpenUrl}" CommandParameter="http://www.pathfinder-fr.org/" />--> |  | ||||||
|                 <!--<ToolbarItem Name="Blog" Text="Blog" Order="Primary" Icon="ic_blog.png" Command="{Binding OpenUrl}" CommandParameter="http://www.pathfinder-fr.org/Blog/" /> |  | ||||||
|                 <ToolbarItem Name="Wikis" Text="Wikis" Order="Primary" Icon="ic_wikis.png" Command="{Binding OpenUrl}" CommandParameter="http://www.pathfinder-fr.org/Wiki/" /> |  | ||||||
|                 <ToolbarItem Name="Forum" Text="Forum" Order="Primary" Icon="ic_forum.png" Command="{Binding OpenUrl}" CommandParameter="http://www.pathfinder-fr.org/Forum/" /> |  | ||||||
| 
 |  | ||||||
|                 <ToolbarItem Name="Gallery2" Text="Galerie" Order="Secondary" Icon="ic_gallery.png" Command="{Binding OpenUrl}" CommandParameter="http://www.pathfinder-fr.org/Media/" /> |  | ||||||
|                 <ToolbarItem Name="Plays2" Text="Parties" Order="Secondary" Icon="ic_plays.png" Command="{Binding OpenUrl}" CommandParameter="http://www.pathfinder-fr.org/Wiki/Parties.MainPage.ashx" /> |  | ||||||
|                 <ToolbarItem Name="Search2" Text="Rechercher" Order="Secondary" Icon="ic_search.png" Command="{Binding OpenUrl}" CommandParameter="http://www.pathfinder-fr.org/search/default.aspx" />--> |  | ||||||
|                 <!--<ToolbarItem Text="Profil" Order="Secondary" Command="{Binding OpenUrl}" CommandParameter="http://www.pathfinder-fr.org/forum/yaf_cp_profile.aspx" /> |  | ||||||
|                 <ToolbarItem Text="Messages privés" Order="Secondary" Command="{Binding OpenUrl}" CommandParameter="http://www.pathfinder-fr.org/forum/default.aspx?g=cp_pm" /> |  | ||||||
|                 <ToolbarItem Text="Connexion" Order="Secondary" Command="{Binding OpenUrl}" CommandParameter="http://www.pathfinder-fr.org/members/login.aspx" /> |  | ||||||
|                 <ToolbarItem Text="Déconnexion" Order="Secondary" Command="{Binding OpenUrl}" CommandParameter="http://www.pathfinder-fr.org/members/logout.aspx" /> |  | ||||||
|                 <ToolbarItem Text="Inscription" Order="Secondary" Command="{Binding OpenUrl}" CommandParameter="http://www.pathfinder-fr.org/members/register.aspx" />--> |  | ||||||
|             </ContentPage.ToolbarItems> |             </ContentPage.ToolbarItems> | ||||||
|             <StackLayout Orientation="Vertical"> |             <StackLayout Orientation="Vertical"> | ||||||
|                 <SearchBar x:Name="SearchBar" SearchCommand="{Binding SearchCommand}" SearchCommandParameter="{Binding Text, Source={x:Reference SearchBar}}"> |                 <SearchBar x:Name="SearchBar" SearchCommand="{Binding SearchCommand}" SearchCommandParameter="{Binding Text, Source={x:Reference SearchBar}}"> | ||||||
|  | @ -119,7 +103,7 @@ | ||||||
|                     IsPullToRefreshEnabled="true" |                     IsPullToRefreshEnabled="true" | ||||||
|                     IsRefreshing="{Binding IsBusy, Mode=OneWay}" |                     IsRefreshing="{Binding IsBusy, Mode=OneWay}" | ||||||
|                     CachingStrategy="RecycleElement" |                     CachingStrategy="RecycleElement" | ||||||
|                  ItemSelected="OnItemSelected"> |                     SelectedItem="{Binding SelectedItem}"> | ||||||
|                     <ListView.ItemTemplate> |                     <ListView.ItemTemplate> | ||||||
|                         <DataTemplate> |                         <DataTemplate> | ||||||
|                             <ViewCell> |                             <ViewCell> | ||||||
|  | @ -128,47 +112,12 @@ | ||||||
|                                         LineBreakMode="NoWrap"  |                                         LineBreakMode="NoWrap"  | ||||||
|                                         Style="{DynamicResource subsubsection}"  |                                         Style="{DynamicResource subsubsection}"  | ||||||
|                                         FontSize="16" /> |                                         FontSize="16" /> | ||||||
|                                     <!--<Label Text="{Binding Description}"  |  | ||||||
|                        LineBreakMode="NoWrap" |  | ||||||
|                        Style="{DynamicResource ListItemDetailTextStyle}" |  | ||||||
|                        FontSize="13" />--> |  | ||||||
|                                 </StackLayout> |                                 </StackLayout> | ||||||
|                             </ViewCell> |                             </ViewCell> | ||||||
|                         </DataTemplate> |                         </DataTemplate> | ||||||
|                     </ListView.ItemTemplate> |                     </ListView.ItemTemplate> | ||||||
|                 </ListView> |                 </ListView> | ||||||
|                 <!--<WebView x:Name="MainView" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" Navigating="OnNavigating" Source="{Binding Source}" />--> |  | ||||||
|                 <!--<ActivityIndicator x:Name="aiProgress" Color="Black" IsRunning="True" IsVisible="True" />--> |  | ||||||
|             </StackLayout> |             </StackLayout> | ||||||
|         </ContentPage> |         </ContentPage> | ||||||
|     </MasterDetailPage.Detail> |     </MasterDetailPage.Detail> | ||||||
| </MasterDetailPage> | </MasterDetailPage> | ||||||
| 
 |  | ||||||
| <!--<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms" |  | ||||||
|             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" |  | ||||||
|             xmlns:views="clr-namespace:AideDeJeu.Views" |  | ||||||
|             x:Class="AideDeJeu.Views.MainPage"> |  | ||||||
|     <TabbedPage.Children> |  | ||||||
|         <NavigationPage Title="Browse"> |  | ||||||
|             <NavigationPage.Icon> |  | ||||||
|                 <OnPlatform x:TypeArguments="FileImageSource"> |  | ||||||
|                     <On Platform="iOS" Value="tab_feed.png"/> |  | ||||||
|                 </OnPlatform> |  | ||||||
|             </NavigationPage.Icon> |  | ||||||
|             <x:Arguments> |  | ||||||
|                 <views:ItemsPage /> |  | ||||||
|             </x:Arguments> |  | ||||||
|         </NavigationPage> |  | ||||||
|          |  | ||||||
|         <NavigationPage Title="About"> |  | ||||||
|             <NavigationPage.Icon> |  | ||||||
|                 <OnPlatform x:TypeArguments="FileImageSource"> |  | ||||||
|                     <On Platform="iOS" Value="tab_about.png"/> |  | ||||||
|                 </OnPlatform> |  | ||||||
|             </NavigationPage.Icon> |  | ||||||
|             <x:Arguments> |  | ||||||
|                 <views:AboutPage /> |  | ||||||
|             </x:Arguments> |  | ||||||
|         </NavigationPage> |  | ||||||
|     </TabbedPage.Children> |  | ||||||
| </TabbedPage>--> |  | ||||||
|  | @ -27,35 +27,6 @@ namespace AideDeJeu.Views | ||||||
|             return true; |             return true; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
|         async void OnItemSelected(object sender, SelectedItemChangedEventArgs args) |  | ||||||
|         { |  | ||||||
|             viewModel.GotoItemCommand.Execute(args.SelectedItem); |  | ||||||
|             //if (args.SelectedItem is Spell) |  | ||||||
|             //{ |  | ||||||
|             //    var item = args.SelectedItem as Spell; |  | ||||||
|             //    if (item == null) |  | ||||||
|             //        return; |  | ||||||
| 
 |  | ||||||
|             //    var vm = new SpellDetailViewModel(item); |  | ||||||
|             //    vm.LoadItemCommand.Execute(null); |  | ||||||
|             //    await Navigation.PushAsync(new SpellDetailPage(vm)); |  | ||||||
|             //} |  | ||||||
|             //else if (args.SelectedItem is Monster) |  | ||||||
|             //{ |  | ||||||
|             //    var item = args.SelectedItem as Monster; |  | ||||||
|             //    if (item == null) |  | ||||||
|             //        return; |  | ||||||
| 
 |  | ||||||
|             //    var vm = new MonsterDetailViewModel(item); |  | ||||||
|             //    vm.LoadItemCommand.Execute(null); |  | ||||||
|             //    await Navigation.PushAsync(new MonsterDetailPage(vm)); |  | ||||||
|             //} |  | ||||||
| 
 |  | ||||||
|             // Manually deselect item. |  | ||||||
|             ItemsListView.SelectedItem = null; |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         protected override void OnAppearing() |         protected override void OnAppearing() | ||||||
|         { |         { | ||||||
|             base.OnAppearing(); |             base.OnAppearing(); | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Yan Maniez
						Yan Maniez