CollectionView not firing SelectionChangedCommand

JohnLivermoreJohnLivermore USMember ✭✭
edited June 26 in Xamarin.Forms

I am using FreshMVVM to bind my view models to my views, and all commanding has worked great so far. However, I am not able to get the SelectionChangedCommand to fire when I change the selection of a CollectionView.

Full source code can be found here

Here is my XAML...

<StackLayout>
    <CollectionView SelectionMode="Single"
                    ItemsSource="{Binding Tags}"
                    SelectedItem="{Binding SelectedTag, Mode=TwoWay}"
                    SelectionChangedCommand="{Binding SelectedTagChangedCommand}">
        <CollectionView.ItemTemplate>
            <DataTemplate>
                <StackLayout>
                    <Label Text="{Binding .}" />
                </StackLayout>
            </DataTemplate>
        </CollectionView.ItemTemplate>
    </CollectionView>
</StackLayout>

And the page model...

public class MainPageModel : FreshBasePageModel
{
    public override void Init(object initData)
    {
        Tags = new ObservableCollection<string>() { "A", "B", "C" };
        SelectedTag = "B";

        base.Init(initData);
    }

    public ObservableCollection<string> Tags { get; set; }

    public string SelectedTag { get; set; }

    public Command SelectedTagChangedCommand
    {
        get
        {
            return new Command(() =>
            {
                   // ****** 
                   // ****** this is never called
                   // ****** 
            });
        }
    }
}

Can anyone see the issue here?

Answers

  • hwj700hwj700 Member ✭✭

    You can find the status of the development of CollectionView in
    https://gist.github.com/hartez/7d0edd4182dbc7de65cebc6c67f72e14
    It states -and that is also my experience- that selection for UWP is still in progress. For Android it works.

  • Amar_BaitAmar_Bait DZMember ✭✭✭✭✭
    edited July 1

    Does SelectedTag changes?

  • JohnLivermoreJohnLivermore USMember ✭✭

    @Amar_Bait yes, the SelectedTag did change, but I was using UWP, and the issues I am experiencing are localized to that platform. And, I have come to find out, CollectionView is not supported yet. It "sort of" works in that it displays the list, etc, but most of the commanding and properties are non-functional. So we are just dropping back to the old ListView for now...

  • Amar_BaitAmar_Bait DZMember ✭✭✭✭✭

    Yeah UWP is clearly dying and Microsoft is abandoning it, they will probably merge it with a new WPF version in the future (.NET 5)

Sign In or Register to comment.