加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – Xamarin表示DisplayAlert在从委托调用的函数调用时不显示

发布时间:2020-12-15 08:38:41 所属栏目:百科 来源:网络整理
导读:当我从大小函数内部调用Greet时,DisplayAlert会按预期显示警告但是当在事件之后从委托调用它时,它将使用正确的名称(Greet Has Called)记录到输出但DisplayAlert不显示. public class CustomPage : ContentPage { ... protected override void OnValidSizeAll
当我从大小函数内部调用Greet时,DisplayAlert会按预期显示警告但是当在事件之后从委托调用它时,它将使用正确的名称(Greet Has Called)记录到输出但DisplayAlert不显示.
public class CustomPage : ContentPage
   {
         ...

        protected override void OnValidSizeAllocated(double width,double height)
        {
            ...

            Greet("Test");

            app.FB.GetName();

            app.FB.NameRecieved += (s,e) =>
            {
                Greet(e.Name);  
            };

        }

        public void Greet(string name)
        {
            Utils.Log("Hey " + name);
            DisplayAlert("Hey " + name,"Welcome","OK");
        }

    }

上面的代码输出“嘿测试”,然后出现一个警告,说“嘿测试,欢迎”,然后输出“嘿Leo”(这是正确的,因为这是来自Facebook帐户的名称)然后没有警报显示.

解决方法

是否在GetName函数内触发了NameReceived?

也许您需要在“= {…};”之后放置app.FB.GetName()块.

如果正确触发了nameReceived,则可能没有在ui线程上运行Greet,
尝试将您的显示代码包装进去

Device.BeginInvokeOnMainThread (() => {
 DisplayAlert("Hey " + name,"OK");
});

如here所述

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读