Xamarin形式DisplayAlert没有显示从由代表呼吁函数调用时 [英] Xamarin forms DisplayAlert not showing when called from a function called by a delegate

查看:977
本文介绍了Xamarin形式DisplayAlert没有显示从由代表呼吁函数调用时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我打电话问候从尺寸功能DisplayAlert将按预期显示然而,当它从一个事件将记录到使用正确的名称后输出的代表呼吁警报内(迎接被调用),但DisplayAlert不显示。

When I call Greet from inside the size function DisplayAlert displays an alert as expected However when it is called from the delegate after an event it will Log to the output with the correct name (Greet Has been Called) but the DisplayAlert does not show.

   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");
        }

    }

在code以上输出嘿测试,然后发出警报大作说:嘿测试,欢迎与OK按钮,然后输出喂狮子座(这是正确的,因为它是从Facebook的名字帐户),但是没有报警显示。

The Code above outputs "Hey Test" and then an alert comes up saying "Hey Test, Welcome" with an OK button then it outputs "Hey Leo" (which is correct because that is the name from the Facebook account) but then no Alert shows.

推荐答案

时的GetName NameReceived函数内部开除了?

Is NameReceived fired inside GetName function?

也许你需要经过+ = {...};放app.FB.GetName()块。

Maybe you need to put app.FB.GetName() after the "+={...};" block.

如果nameReceived正确解雇也许迎接未在UI线程运行,
尝试换你显示code在

If nameReceived is correctly fired maybe Greet is not running on ui thread, try wrap your display code in

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

如所描述

<一href=\"http://developer.xamarin.com/api/member/Xamarin.Forms.Device.BeginInvokeOnMainThread(System.Action)/\"相对=nofollow称号=这里>这里

这篇关于Xamarin形式DisplayAlert没有显示从由代表呼吁函数调用时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆