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.