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

ActivityIndicator in ListView item

$
0
0

Hello,

I have a ListView. When an item is tapped, an asynchronous call is made that could take a while, so I want to show an ActivityIndicator inside of the item that was tapped. However, I'm not seeing the indicator. I've got several other activity indicators in my project that work great, but this one is really giving me trouble. I think it may have something to do with the bindings, as my other indicators just directly change the properties of the indicators themselves (but I don't think it's possible to access the individual indicators within the list).

Here's the code for ItemSelected:

    list.ItemSelected += async (o, e) =>
                {
                    if (e.SelectedItem == null || busy)
                    {
                        return;
                    }
                    else
                    {
                        Row row = (Row)e.SelectedItem;
                        row.loading = true;
                        await Task.Yield();
                        await Navigation.PushAsync(new NextPage(row));
                    }
                };

For the items:

var listDataTemplate = new DataTemplate(() =>
{
    //all the other stuff in the list item

               var ai = new ActivityIndicator();
               ai.IsEnabled = false;
               ai.IsVisible = false;
               ai.IsRunning = false;
               ai.SetBinding(ActivityIndicator.IsEnabledProperty, "loading");
               ai.SetBinding(ActivityIndicator.IsRunningProperty, "loading");
               ai.SetBinding(ActivityIndicator.IsVisibleProperty, "loading");

    //etc...
});

And the Row class:

    public class Row
    {
        //all of my other fields

        private bool busy = false;

            public bool loading
            {
                get { return busy; }
                set
                {
                    if (busy == value)
                        return;

                    busy = value;
                }
            }
    }

Viewing all articles
Browse latest Browse all 89864

Trending Articles



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