Sajid Hussain

Sajid Hussain

  • 1.1k
  • 509
  • 94.3k

Unable to navigate in xamarin Cross plateform application

Jul 22 2017 3:08 PM
I am working in xamarin cross plateform application,and new one in this domain,have to contend page Login,and main page,after clicking on login user must redirect to main page. here is the code.
 
App.cs
 
public App()
{
InitializeComponent();
MainPage = new NavigationPage(new Login());
}
 
Login.cs
 
async void _client_ValidateUserCompleted(object sender, FypWcf.ValidateUserCompletedEventArgs e)
{
try
{
if (e.Result == true)
{
await Navigation.PushAsync(new MainForm());
}
else
{
await DisplayAlert("Oops", "Credentials are incorrect", "Cancel");
}
}
catch (Exception ex)
{
await DisplayAlert(ex.Message, "Credentials are incorrect", "Cancel");
}
}
private void Button_Clicked_1(object sender, EventArgs e)
{
try
{
var endpoint = new EndpointAddress("http://192.168.43.101/FYP_Admin/webservices/cmsservice.svc");
var binding = new BasicHttpBinding
{
Name = "basicHttpBinding",
MaxBufferSize = 2147483647,
MaxReceivedMessageSize = 2147483647
};
TimeSpan timeout = new TimeSpan(0, 0, 30);
binding.SendTimeout = timeout;
binding.OpenTimeout = timeout;
binding.ReceiveTimeout = timeout;
_client = new FypWcf.CMSServiceClient(binding, endpoint);
string username = usernameEntry.Text.Trim();
string password = passwordEntry.Text.Trim();
_client.ValidateUserAsync(username, password);
_client.ValidateUserCompleted += _client_ValidateUserCompleted;
}
catch (Exception ex)
{
DisplayAlert(ex.Message, "Credentials are incorrect", "Cancel");
}
}
 
 Problem is when login button is clicked,and debug the code its through exception,
 

only the original thread that created a view hierarchy can touch its views

did google but no solution was fruitful. 
 
 
 
 

Answers (3)