Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

ListView with SelectedItem vs TextCell Command

$
0
0

I have a scenario where I need to take the value of a selected TextCell and use it to update a Label outside of the ListView. I notice that ListView has a SelectedItem property and the TextCell has a Command property. What is the difference between these?

As a more general design question (I am using Xamarin MVVM), how should I go about doing the update? Currently I was thinking of using the ListView SelectedItem property and binding it (Two-Way) with my VM. Then in the Setter I would update the VM propery that the label is bounded to.... Problem is that I have an async task that I need to do as it will translate the TextCell value to what I need the Label value to be.... How should I do this?

I have read a lot about behaviors and using those but I haven't even begun learning about those yet. I also played with the idea of using Task.Run for getting around the async issue. Also I thought about using the MessagingCenter but that seems to be for VM -> VM.

View:

<ListView x:Name="ResultsList"
                          SelectedItem="{Binding SelectedDestinationItem,
                                                 Mode=TwoWay}">
                    <ListView.ItemTemplate>
                        <DataTemplate>
                            <TextCell Text="{Binding Description}" Detail="{Binding Place_ID}" Com />
                        </DataTemplate>
                    </ListView.ItemTemplate>
                </ListView>
<Label Text="{Binding Current.Destination}"/>

And for the VM:

        public AutoCompletePrediction SelectedDestinationItem
        {
            get => _selectedDestinationItem;
            set
            {
                SetProperty(ref _selectedDestinationItem, value, "SelectedDestinationItem");
                if (_selectedDestinationItem == null) return;
                var place = await Places.GetPlace(_selectedDestinationItem.Place_ID, Constants.PlacesApiKey); //not valid
                Current.Destination = place;
                SelectedDestinationItem = null;


            }
        }

        private AutoCompletePrediction _selectedDestinationItem;

Viewing all articles
Browse latest Browse all 204402

Trending Articles



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