mirror of
				https://github.com/Nioux/AideDeJeu.git
				synced 2025-10-31 15:36:07 +00:00 
			
		
		
		
	Binding picker
This commit is contained in:
		
							parent
							
								
									bb18b4b612
								
							
						
					
					
						commit
						5c4e100b16
					
				
					 4 changed files with 95 additions and 22 deletions
				
			
		|  | @ -8,7 +8,7 @@ namespace AideDeJeu.ViewModels | ||||||
|     public class PickerViewModel<T> : BaseViewModel where T:class |     public class PickerViewModel<T> : BaseViewModel where T:class | ||||||
|     { |     { | ||||||
|         private string _Title = null; |         private string _Title = null; | ||||||
|         public string Title |         public new string Title | ||||||
|         { |         { | ||||||
|             get |             get | ||||||
|             { |             { | ||||||
|  | @ -20,8 +20,8 @@ namespace AideDeJeu.ViewModels | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         private List<T> _Items = null; |         private System.Collections.IEnumerable _Items = null; | ||||||
|         public List<T> Items |         public System.Collections.IEnumerable Items | ||||||
|         { |         { | ||||||
|             get |             get | ||||||
|             { |             { | ||||||
|  |  | ||||||
|  | @ -74,7 +74,9 @@ | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|                 <views:StringPickerView /> |                 <!--<views:StringPickerView Title="Trait de personnalité" IsVisible="{Binding PersonalityTraits.IsSuccessfullyCompleted}" ItemsSource="{Binding PersonalityTraits.Result}" />--> | ||||||
|  |                 <views:StringPickerView BindingContext="{Binding}" Title="Trait de personnalité" IsVisible="{Binding PersonalityIdeals.IsSuccessfullyCompleted}" ItemsSource="{Binding PersonalityIdeals.Result}" /> | ||||||
|  |                 <!--SelectedItem="{Binding SelectedPlayerCharacter.PersonalityTrait, Mode=TwoWay}"--> | ||||||
| 
 | 
 | ||||||
|                 <Button Visual="Material" IsVisible="{Binding PersonalityIdeals.IsSuccessfullyCompleted}" Text="Idéal" Command="{Binding PersonalityIdealPickerCommand}" CommandParameter="{Binding PersonalityIdeals.Result}" /> |                 <Button Visual="Material" IsVisible="{Binding PersonalityIdeals.IsSuccessfullyCompleted}" Text="Idéal" Command="{Binding PersonalityIdealPickerCommand}" CommandParameter="{Binding PersonalityIdeals.Result}" /> | ||||||
|                 <mdview:MarkdownView Theme="{StaticResource MonsterMarkdownTheme}" IsVisible="{Binding PersonalityIdeals.IsSuccessfullyCompleted}" HorizontalOptions="FillAndExpand" Markdown="{Binding SelectedPlayerCharacter.PersonalityIdeal}" /> |                 <mdview:MarkdownView Theme="{StaticResource MonsterMarkdownTheme}" IsVisible="{Binding PersonalityIdeals.IsSuccessfullyCompleted}" HorizontalOptions="FillAndExpand" Markdown="{Binding SelectedPlayerCharacter.PersonalityIdeal}" /> | ||||||
|  |  | ||||||
|  | @ -1,23 +1,27 @@ | ||||||
| <?xml version="1.0" encoding="UTF-8"?> | <?xml version="1.0" encoding="UTF-8"?> | ||||||
| <ContentView xmlns="http://xamarin.com/schemas/2014/forms"  | <StackLayout xmlns="http://xamarin.com/schemas/2014/forms"  | ||||||
|              xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" |              xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | ||||||
|         xmlns:tools="clr-namespace:AideDeJeu.Tools" |         xmlns:tools="clr-namespace:AideDeJeu.Tools" | ||||||
|         xmlns:mdview="clr-namespace:Xam.Forms.Markdown" |         xmlns:mdview="clr-namespace:Xam.Forms.Markdown" | ||||||
|              x:Class="AideDeJeu.Views.StringPickerView"> |              x:Class="AideDeJeu.Views.StringPickerView" | ||||||
|     <ContentView.Resources> |              x:Name="this"> | ||||||
|  |     <StackLayout.Resources> | ||||||
|         <ResourceDictionary> |         <ResourceDictionary> | ||||||
|             <tools:MonsterMarkdownTheme x:Key="MonsterMarkdownTheme" /> |             <tools:MonsterMarkdownTheme x:Key="MonsterMarkdownTheme" /> | ||||||
|             <tools:NullToFalseConverter x:Key="NullToFalseConverter" /> |             <tools:NullToFalseConverter x:Key="NullToFalseConverter" /> | ||||||
|         </ResourceDictionary> |         </ResourceDictionary> | ||||||
|     </ContentView.Resources> |     </StackLayout.Resources> | ||||||
|     <ContentView.Content> |     <mdview:MarkdownView Theme="{StaticResource MonsterMarkdownTheme}" Markdown="{Binding Title, Source={x:Reference this}, StringFormat='## [{0}](#)'}" IsEnabled="False" /> | ||||||
|         <StackLayout IsVisible="{Binding PersonalityTraits.IsSuccessfullyCompleted}"> |     <!--<mdview:MarkdownView Theme="{StaticResource MonsterMarkdownTheme}" Markdown="{Binding SelectedItem, Source={x:Reference this}}" />--> | ||||||
|             <mdview:MarkdownView Theme="{StaticResource MonsterMarkdownTheme}" Markdown="## [Trait de personnalité](#)" IsEnabled="False" /> |     <StackLayout BindableLayout.ItemsSource="{Binding ItemsSource, Source={x:Reference this}}"> | ||||||
|             <mdview:MarkdownView Theme="{StaticResource MonsterMarkdownTheme}" Markdown="{Binding SelectedPlayerCharacter.PersonalityTrait}" /> |         <BindableLayout.ItemTemplate> | ||||||
|             <StackLayout.GestureRecognizers> |             <DataTemplate> | ||||||
|                 <ClickGestureRecognizer Command="{Binding PersonalityTraitPickerCommand}" CommandParameter="{Binding PersonalityTraits.Result}" /> |                 <Label Text="{Binding}" /> | ||||||
|                 <TapGestureRecognizer Command="{Binding PersonalityTraitPickerCommand}" CommandParameter="{Binding PersonalityTraits.Result}" /> |             </DataTemplate> | ||||||
|             </StackLayout.GestureRecognizers> |         </BindableLayout.ItemTemplate> | ||||||
|         </StackLayout> |     </StackLayout> | ||||||
|     </ContentView.Content> |     <StackLayout.GestureRecognizers> | ||||||
| </ContentView> |         <ClickGestureRecognizer Command="{Binding PickerCommand, Source={x:Reference this}}" CommandParameter="{Binding ItemsSource, Source={x:Reference this}}" /> | ||||||
|  |         <TapGestureRecognizer Command="{Binding PickerCommand, Source={x:Reference this}}" CommandParameter="{Binding ItemsSource, Source={x:Reference this}}" /> | ||||||
|  |     </StackLayout.GestureRecognizers> | ||||||
|  | </StackLayout> | ||||||
|  | @ -1,20 +1,87 @@ | ||||||
| using System; | using AideDeJeu.ViewModels; | ||||||
|  | using System; | ||||||
| using System.Collections.Generic; | using System.Collections.Generic; | ||||||
| using System.Linq; | using System.Linq; | ||||||
| using System.Text; | using System.Text; | ||||||
| using System.Threading.Tasks; | using System.Threading.Tasks; | ||||||
| 
 | using System.Windows.Input; | ||||||
| using Xamarin.Forms; | using Xamarin.Forms; | ||||||
| using Xamarin.Forms.Xaml; | using Xamarin.Forms.Xaml; | ||||||
| 
 | 
 | ||||||
| namespace AideDeJeu.Views | namespace AideDeJeu.Views | ||||||
| { | { | ||||||
|     [XamlCompilation(XamlCompilationOptions.Compile)] |     [XamlCompilation(XamlCompilationOptions.Compile)] | ||||||
|     public partial class StringPickerView : ContentView |     public partial class StringPickerView : StackLayout | ||||||
|     { |     { | ||||||
|  |         public MainViewModel Main | ||||||
|  |         { | ||||||
|  |             get | ||||||
|  |             { | ||||||
|  |                 return DependencyService.Get<MainViewModel>(); | ||||||
|  |             } | ||||||
|  |         } | ||||||
|         public StringPickerView() |         public StringPickerView() | ||||||
|         { |         { | ||||||
|             InitializeComponent(); |             InitializeComponent(); | ||||||
|  |             BindingContext = this; | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         public string Title | ||||||
|  |         { | ||||||
|  |             get { return (string)GetValue(TitleProperty); } | ||||||
|  |             set { SetValue(TitleProperty, value); } | ||||||
|  |         } | ||||||
|  |         public static readonly BindableProperty TitleProperty = BindableProperty.Create( | ||||||
|  |             nameof(Title),  | ||||||
|  |             typeof(string),  | ||||||
|  |             typeof(StringPickerView), | ||||||
|  |             defaultValue: default(string)); | ||||||
|  | 
 | ||||||
|  |         public string SelectedItem | ||||||
|  |         { | ||||||
|  |             get { return (string)GetValue(SelectedItemProperty); } | ||||||
|  |             set { SetValue(SelectedItemProperty, value); } | ||||||
|  |         } | ||||||
|  |         public static readonly BindableProperty SelectedItemProperty = BindableProperty.Create( | ||||||
|  |             nameof(SelectedItem),  | ||||||
|  |             typeof(string),  | ||||||
|  |             typeof(StringPickerView),  | ||||||
|  |             defaultValue: default(string),  | ||||||
|  |             defaultBindingMode: BindingMode.TwoWay); | ||||||
|  | 
 | ||||||
|  |         public System.Collections.IEnumerable ItemsSource | ||||||
|  |         { | ||||||
|  |             get { return (System.Collections.IEnumerable)GetValue(ItemsSourceProperty); } | ||||||
|  |             set { SetValue(ItemsSourceProperty, value); } | ||||||
|  |         } | ||||||
|  |         //public static readonly BindableProperty ItemsSourceProperty = BindableProperty.Create( | ||||||
|  |         //    nameof(ItemsSource),  | ||||||
|  |         //    typeof(System.Collections.IList),  | ||||||
|  |         //    typeof(StringPickerView), | ||||||
|  |         //    defaultValue: new List<string>()); | ||||||
|  |         public static readonly BindableProperty ItemsSourceProperty = | ||||||
|  |             BindableProperty.Create( | ||||||
|  |                 nameof(ItemsSource),  | ||||||
|  |                 typeof(System.Collections.IEnumerable),  | ||||||
|  |                 typeof(StringPickerView),  | ||||||
|  |                 default(System.Collections.IEnumerable)); | ||||||
|  | 
 | ||||||
|  |         public ICommand PickerCommand | ||||||
|  |         { | ||||||
|  |             get | ||||||
|  |             { | ||||||
|  |                 return new Command<System.Collections.IList>(async (strings) => SelectedItem = await ExecuteStringPickerCommandAsync(strings)); | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |         private async Task<string> ExecuteStringPickerCommandAsync(System.Collections.IEnumerable strings) | ||||||
|  |         { | ||||||
|  |             var picker = new Views.StringPicker(); | ||||||
|  |             var vm = picker.ViewModel; | ||||||
|  |             vm.Items = strings; | ||||||
|  |             await Main.Navigator.Navigation.PushModalAsync(picker, true); | ||||||
|  |             var result = await vm.PickValueAsync(); | ||||||
|  |             await Main.Navigator.Navigation.PopModalAsync(true); | ||||||
|  |             return result; | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Yan Maniez
						Yan Maniez