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

Remove / move

This commit is contained in:
Yan Maniez 2018-09-18 23:02:50 +02:00
parent 60af7bb029
commit 861b8c64d2
2 changed files with 69 additions and 6 deletions

View file

@ -7,6 +7,8 @@ using System.Linq;
using System.Runtime.Serialization.Json;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using Xamarin.Forms;
using Xamarin.Forms.Internals;
namespace AideDeJeu.ViewModels
@ -25,6 +27,7 @@ namespace AideDeJeu.ViewModels
"Bestiaire",
"Sac",
};
private int _BookmarkCollectionIndex = 0;
public int BookmarkCollectionIndex
{
@ -49,7 +52,63 @@ namespace AideDeJeu.ViewModels
{
SetProperty(ref _BookmarkCollection, value);
}
}
}
private ICommand _RemoveItemCommand = null;
public ICommand RemoveItemCommand
{
get
{
return _RemoveItemCommand ?? (_RemoveItemCommand = new Command<Item>(ExecuteRemoveItemCommand));
}
}
private void ExecuteRemoveItemCommand(Item item)
{
BookmarkCollection.Remove(item);
}
private ICommand _MoveUpItemCommand = null;
public ICommand MoveUpItemCommand
{
get
{
return _MoveUpItemCommand ?? (_MoveUpItemCommand = new Command<Item>(ExecuteMoveUpItemCommand));
}
}
private void ExecuteMoveUpItemCommand(Item item)
{
var index = BookmarkCollection.IndexOf(item);
if (index > 0)
{
BookmarkCollection.RemoveAt(index);
BookmarkCollection.Insert(index - 1, item);
}
}
private ICommand _MoveDownItemCommand = null;
public ICommand MoveDownItemCommand
{
get
{
return _MoveDownItemCommand ?? (_MoveDownItemCommand = new Command<Item>(ExecuteMoveDownItemCommand));
}
}
private void ExecuteMoveDownItemCommand(Item item)
{
var index = BookmarkCollection.IndexOf(item);
if (index < BookmarkCollection.Count - 1)
{
BookmarkCollection.RemoveAt(index);
BookmarkCollection.Insert(index + 1, item);
}
}
public async Task<List<Item>> GetBookmarkCollection(string key)
{

View file

@ -22,17 +22,21 @@
<Entry Grid.Column="0" Grid.Row="0" Style="{StaticResource heading1}" HorizontalOptions="FillAndExpand" />
<ListView Grid.Column="0" Grid.Row="1" x:Name="ItemsListView" ItemsSource="{Binding BookmarkCollection}" VerticalOptions="FillAndExpand" HasUnevenRows="true" CachingStrategy="RecycleElement" SelectedItem="{Binding SelectedItem}" ItemTapped="ItemsListView_ItemTapped">
<ListView Grid.Column="0" Grid.Row="1" x:Name="ItemsListView" SelectionMode="None" ItemsSource="{Binding BookmarkCollection}" VerticalOptions="FillAndExpand">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Grid Padding="10">
<Grid.RowDefinitions>
<RowDefinition Height="auto" />
<RowDefinition Height="auto" />
<RowDefinition Height="auto" />
</Grid.RowDefinitions>
<Label Grid.Column="0" Grid.Row="0" Grid.ColumnSpan="3" Text="{Binding Name}" LineBreakMode="WordWrap" Style="{DynamicResource heading3}" FontSize="16" />
<Label Grid.Column="0" Grid.Row="1" Grid.ColumnSpan="3" Text="{Binding Link}" LineBreakMode="WordWrap" Style="{DynamicResource heading3}" FontSize="12" />
<Image Grid.Column="0" Grid.Row="2" BackgroundColor="#FF0000" WidthRequest="20" HeightRequest="20" />
<Image Grid.Column="1" Grid.Row="2" BackgroundColor="#00FF00" WidthRequest="20" HeightRequest="20" />
<Image Grid.Column="2" Grid.Row="2" BackgroundColor="#0000FF" WidthRequest="20" HeightRequest="20" />
<Button Grid.Column="0" Grid.Row="2" Text="Sypprimer" Command="{Binding BindingContext.RemoveItemCommand, Source={x:Reference This}}" CommandParameter="{Binding}" />
<Button Grid.Column="1" Grid.Row="2" Text="Monter" Command="{Binding BindingContext.MoveUpItemCommand, Source={x:Reference This}}" CommandParameter="{Binding}" />
<Button Grid.Column="2" Grid.Row="2" Text="Descendre" Command="{Binding BindingContext.MoveDownItemCommand, Source={x:Reference This}}" CommandParameter="{Binding}" />
</Grid>
</ViewCell>
</DataTemplate>