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

Phoneword example: encapsulate Xamarin.Forms don't work for Android.

$
0
0

Hi, I'm very new to C# and Xamarin, so please excuse me.

I'd like to encapsulate the Xamarin.Forms methods from the MainPage into an own Forms.cs.
The UWP works fine, but the Android project freeze and don't show the DisplayAlert.

I have adaptet the Phoneword example from www. developer.xamarin.com/samples/xamarin-forms/Phoneword/

MainPage.xaml.cs

    using System;

    namespace Phoneword
    {
        public partial class MainPage
        {
            Forms forms = new Forms();
            async void OnCall(object sender, EventArgs e)
            {
                if (await forms.FormsDisplayAlert(      // Here the Android project freeze and dont show the DisplayAlert
                    "Dial a Number",
                    "Would you like to call " + translatedNumber + "?",
                    "Yes",
                    "No"))
                {
                    var dialer = forms.GetDependencyService();
                    if (dialer != null)
                        dialer.Dial(translatedNumber);
                }
            }
        }
    }

Forms.cs

        using System.Threading.Tasks;
        using Xamarin.Forms;

        namespace Phoneword 
        {
            public class Forms : ContentPage
            {
                public Task<bool> FormsDisplayAlert(string title, string message, string accept, string cancel)
                {
                    return DisplayAlert(title, message, accept, cancel);
                }
                public IDialer GetDependencyService()
                {
                    return DependencyService.Get<IDialer>();
                }
            }
        }

I am very grateful for any help.


Viewing all articles
Browse latest Browse all 77050

Trending Articles



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