Click here to Skip to main content
15,889,808 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.

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.

What I have tried:

C#
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");
}
}
Posted
Updated 2-Aug-17 20:46pm
v2

1 solution

(
await Navigation.PushAsync(new MainForm());
) Remove await and try
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900