滚动视图渲染器上的ObjectDisposedException

时间:2019-02-05 09:00:35

标签: xaml mvvm xamarin.forms xamarin.android event-handling

我在Xamarin应用程序中触发了以下事件:

AppEvents.Instance.UI.RiseSearchStringTypingEvent(this, new EventArgs());

在每次触发事件时(在搜索字段中的每个输入上), HomePage.xaml.cs 用户代码背后的代码都会自动滚动到顶部

void OnSearchStringTyping(object sender, EventArgs e)
{
    scrollView.ScrollToAsync(0.0, 0.0, true);
}

当搜索字符串完成并且用户点击了提交按钮时, Oncompleted()方法将在 SearchHeaderView.xaml.cs 上调用,该方法导航到 SearchPage

void OnCompleted(object sender, EventArgs e)
{
    var tag = this + ".OnCompleted";
    try
    {
        if (string.Compare(LastSearchText, SearchEntry.Text) == 0) return

        if (Device.RuntimePlatform == Device.Android)
        {
            SearchRequest();
        }
        else if (Device.RuntimePlatform == Device.iOS)
        {
            var task = new Task(SearchRequest);
            task.Start();
        }

        LastSearchText = SearchEntry.Text;
    }
    catch (Exception ex)
    {
        Track.Exception(tag, ex);
    }
}

此过程在iOS平台上可以完美运行...但是在android中,当我提交搜索字符串时,应用程序崩溃,并在 ScrollView

上出现 ObjectDisposedException >

我认为问题在于应用程序试图在导航离开首页后 之后再次向上滚动视图。 Android上的 SearchRequest()方法未在新线程中调用,但iOS被调用。我怎样才能解决这个问题?我不能仅仅使该方法被异步调用,因为那时搜索不起作用。

0 个答案:

没有答案