Skip to content

Instantly share code, notes, and snippets.

@AmSmart
Created September 2, 2020 00:29
Show Gist options
  • Save AmSmart/ce74930d26c40e13a6003954c123a9ee to your computer and use it in GitHub Desktop.
Save AmSmart/ce74930d26c40e13a6003954c123a9ee to your computer and use it in GitHub Desktop.
SelcetedItems not working properly (Xamarin.Forms CollectionView)
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
x:Class="StatusSaver.Views.VideosPage">
<ContentPage.ToolbarItems>
<ToolbarItem Text="Save" Command="{Binding Save}"/>
<ToolbarItem Text="Save As" Command="{Binding SaveAs}"/>
<ToolbarItem Text="Join and Save" Command="{Binding JoinAndSave}"/>
<ToolbarItem Text="Cancel" Command="{Binding Cancel}"/>
</ContentPage.ToolbarItems>
<ContentPage.Content>
<CollectionView ItemsSource="{Binding Videos}"
ItemsLayout="VerticalGrid, 2"
SelectionMode="Multiple"
SelectionChangedCommand="{Binding SelectionChanged}"
SelectedItems="{Binding SelectedItems, Mode=TwoWay}"
x:Name="colView">
<CollectionView.ItemTemplate>
<DataTemplate>
<Image Source="{Binding ImageSource}"/>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
</ContentPage.Content>
</ContentPage>
public class VideosPageViewModel
{
private readonly IPageManager _pageManager;
private readonly IMediaManager _mediaManager;
private readonly IMessage _message;
public VideosPageViewModel(IPathManager pathManager, IPageManager pageManager,
IThumbnailGenerator thumbnailGenerator, IMediaManager mediaManager, IMessage message)
{
// ViewModel intialistion
}
public ObservableCollection<Video> Videos { get; set; }
public ICommand SelectionChanged { get; set; }
public ICommand Save { get; set; }
public ICommand SaveAs { get; set; }
public ICommand JoinAndSave { get; set; }
public ICommand Cancel { get; set; }
public IList<object> SelectedItems { get; set; }
private void OnSelectionChanged()
{
}
private void OnCancel()
{
SelectedItems = null;
_message.LongAlert("All selections cancelled");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment