Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 89864

CollectionView not firing SelectionChangedCommand

$
0
0

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?


Viewing all articles
Browse latest Browse all 89864

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>