mirror of
https://github.com/Nioux/AideDeJeu.git
synced 2025-10-30 15:06:06 +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
|
||||
{
|
||||
private string _Title = null;
|
||||
public string Title
|
||||
public new string Title
|
||||
{
|
||||
get
|
||||
{
|
||||
|
|
@ -20,8 +20,8 @@ namespace AideDeJeu.ViewModels
|
|||
}
|
||||
}
|
||||
|
||||
private List<T> _Items = null;
|
||||
public List<T> Items
|
||||
private System.Collections.IEnumerable _Items = null;
|
||||
public System.Collections.IEnumerable Items
|
||||
{
|
||||
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}" />
|
||||
<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"?>
|
||||
<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:tools="clr-namespace:AideDeJeu.Tools"
|
||||
xmlns:mdview="clr-namespace:Xam.Forms.Markdown"
|
||||
x:Class="AideDeJeu.Views.StringPickerView">
|
||||
<ContentView.Resources>
|
||||
x:Class="AideDeJeu.Views.StringPickerView"
|
||||
x:Name="this">
|
||||
<StackLayout.Resources>
|
||||
<ResourceDictionary>
|
||||
<tools:MonsterMarkdownTheme x:Key="MonsterMarkdownTheme" />
|
||||
<tools:NullToFalseConverter x:Key="NullToFalseConverter" />
|
||||
</ResourceDictionary>
|
||||
</ContentView.Resources>
|
||||
<ContentView.Content>
|
||||
<StackLayout IsVisible="{Binding PersonalityTraits.IsSuccessfullyCompleted}">
|
||||
<mdview:MarkdownView Theme="{StaticResource MonsterMarkdownTheme}" Markdown="## [Trait de personnalité](#)" IsEnabled="False" />
|
||||
<mdview:MarkdownView Theme="{StaticResource MonsterMarkdownTheme}" Markdown="{Binding SelectedPlayerCharacter.PersonalityTrait}" />
|
||||
<StackLayout.GestureRecognizers>
|
||||
<ClickGestureRecognizer Command="{Binding PersonalityTraitPickerCommand}" CommandParameter="{Binding PersonalityTraits.Result}" />
|
||||
<TapGestureRecognizer Command="{Binding PersonalityTraitPickerCommand}" CommandParameter="{Binding PersonalityTraits.Result}" />
|
||||
</StackLayout.GestureRecognizers>
|
||||
</StackLayout>
|
||||
</ContentView.Content>
|
||||
</ContentView>
|
||||
</StackLayout.Resources>
|
||||
<mdview:MarkdownView Theme="{StaticResource MonsterMarkdownTheme}" Markdown="{Binding Title, Source={x:Reference this}, StringFormat='## [{0}](#)'}" IsEnabled="False" />
|
||||
<!--<mdview:MarkdownView Theme="{StaticResource MonsterMarkdownTheme}" Markdown="{Binding SelectedItem, Source={x:Reference this}}" />-->
|
||||
<StackLayout BindableLayout.ItemsSource="{Binding ItemsSource, Source={x:Reference this}}">
|
||||
<BindableLayout.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<Label Text="{Binding}" />
|
||||
</DataTemplate>
|
||||
</BindableLayout.ItemTemplate>
|
||||
</StackLayout>
|
||||
<StackLayout.GestureRecognizers>
|
||||
<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.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using System.Windows.Input;
|
||||
using Xamarin.Forms;
|
||||
using Xamarin.Forms.Xaml;
|
||||
|
||||
namespace AideDeJeu.Views
|
||||
{
|
||||
[XamlCompilation(XamlCompilationOptions.Compile)]
|
||||
public partial class StringPickerView : ContentView
|
||||
public partial class StringPickerView : StackLayout
|
||||
{
|
||||
public MainViewModel Main
|
||||
{
|
||||
get
|
||||
{
|
||||
return DependencyService.Get<MainViewModel>();
|
||||
}
|
||||
}
|
||||
public StringPickerView()
|
||||
{
|
||||
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