ViewCell with ContextAction Causes app to freeze

KyleClarkKyleClark USMember
edited November 2016 in Xamarin.Forms

I'm trying to add a Delete ContextAction to a basic ViewCell, but when I run the application it freezes when navigating to this page. I'm testing on iOS, and my current code is very similar to the example code supplied in the documentation:

Xaml View:

<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" 
        xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
        x:Class="myApp.Views.DevelopmentPage">
    <ContentPage.Content>
        <ListView x:Name="TestListView" 
            ItemsSource="{Binding TestRows}">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <ViewCell>
                        <ViewCell.ContextActions>
                            <MenuItem Text="Delete" 
                                Clicked="OnDelete" />
                        </ViewCell.ContextActions>
                        <StackLayout>
                            <Label Text="{Binding .}" />
                        </StackLayout>
                    </ViewCell>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
    </ContentPage.Content>
</ContentPage>

CodeBehind:

using System;
using myApp.ViewModels;
using Xamarin.Forms;

namespace myApp.Views
{
    public partial class DevelopmentPage : ContentPage
    {
        private DevelopmentViewModel _vm;

        public DevelopmentPage()
        {
            _vm = new DevelopmentViewModel();
            BindingContext = _vm;
            InitializeComponent();
        }

        protected override void OnAppearing()
        {
            _vm.LoadData();
            base.OnAppearing();
        }

        public void OnDelete(object sender, EventArgs e)
        {
                // Do Nothing
        }
    }
}

ViewModel:

using System.Collections.ObjectModel;

namespace myApp.ViewModels
{
    public class DevelopmentViewModel : ViewModel
    {
        public ObservableCollection<string> TestRows { get; set; }

        public DevelopmentViewModel()
        {
            TestRows = new ObservableCollection<string>();
        }

        public void LoadData()
        {
            TestRows.Clear();
            TestRows.Add("Hello 1");
            TestRows.Add("Hello 2");
        }
    }
}

Any help would be greatly appreciated!

Answers

  • MusicnotesDevMusicnotesDev USMember ✭✭

    Having the same issue here. If I take out the ContextActions the whole app functions fine.

    This is after converting to a "PrismApplication" and using their DI container. Not sure why this would effect the XAML ContextActions ...

    Very frustrating!

Sign In or Register to comment.