just wondering basically i have an Azure authentication system that opens when clicking on a facebook button or twitter button it then asks to authenticate the app and once logged in displays a UIalertview with the options to click "OK" or "Cancel".
I was wondering how once they clicked ok i could get it to display the next View?
I know my uialertview is called alert - so was thinking it would alert.Clicked (); then something in there but not sure what.
Here is the method that is processing the login and the alertview if someone can get back to me fast.
private void DoLogin(MobileServiceAuthenticationProvider provider)
{
var task = this.client.LoginAsync(this, provider).ContinueWith(t => {
MobileServiceUser user = t.Result;
this.BeginInvokeOnMainThread(() => {
UIAlertView alert = new UIAlertView("Logged In!", string.Format ("Hello user {0}", user.UserId),
null, "OK", new string[] {"Cancel"});
alert.Clicked();
alert.Show ();
});
});
}
Thanks
For example you could do this:
alert.Clicked += (sender, args) =>
{
// check if the user NOT pressed the cancel button
if (args.ButtonIndex != alert.CancelButtonIndex)
{
// present your next UIViewController, something like this
NavigationController.PushViewController(new YourNextViewController(), true);
}
};
For more information about UIAlertView check out it's documentation:
https://developer.apple.com/library/prerelease/ios/documentation/UIKit/Reference/UIAlertView_Class/index.html
Related
I need to pass some additional information with a button press. From what I could gather reading on the web I should use a button tag.
So far I have this
Button button = new Button(this);
button.Text = "Test Button";
button.SetBackgroundColor(Android.Graphics.Color.Black);
button.SetTextColor(Android.Graphics.Color.White);
button.Tag = "hello";
button.Click += ClickEvent;
And this is the handler:
public void ClickEvent(object sender, EventArgs e)
{
Android.Widget.Button button = (Android.Widget.Button)sender;
var test = button.Tag;
}
This works, but I need to be able to pass 3 ints of data. I have tried using an array but I have no idea how to read it in the handler as it comes back as a java.object.
Can anyone please push me in the right direction?
I am developing mobile application using Xamarin.Forms. I have requirement of getting input in the dialog box. So, i have used UIAlertView for getting text input as like below.
I need to prevent an UIAlertView from closing on button click. I need to retain the UIAlertView dialog box even after the action initiated.
Can anyone please help me on this?
Regards,
Karthikeyan
You could create a custom UIView for this using a Xib file, however if you have no objection to the dialog closing and reopening should it encounter a validation issue then the following would work fine.
EDIT: Adjusted to allow you to pass back the validation message, as the primary message on the UIAlertView.
private string message = string.Empty();
public void recursiveDialog()
{
string input = string.Empty();
if(message == string.Empty()) { message = "Please enter the view name"}
var alert = UIAlertController.Create ("Save View", message, UIAlertControllerStyle.Alert);
alert.AddTextField ((field) => {
field.Placeholder = "view name";});
alert.AddAction (UIAlertAction.Create ("Cancel", UIAlertActionStyle.Cancel, null));
alert.AddAction (UIAlertAction.Create ("Save", UIAlertActionStyle.Default, action => {
input = alert.TextFields[0].Text
}));
if (alert.PopoverPresentationController != null)
alert.PopoverPresentationController.BarButtonItem = myItem;
PresentViewController (alert, animated: true,
action => {
// when a dialog is selected and returns, run validation
if(input == [whatever you want to use to validate it against])
{
// it failed because it already exists for example so change our message
message = "That view name already exists, try again.";
// already exists, so re-run method.
recursiveDialog();
}
else
{
// doesn't alread exist so carry on with whatever you want to do with the name provided.
// clear your message variable
message = string.Empty();
}
});
}
I have a question on Xamarin.Forms, I'm trying to navigate back page from detail page when UIAlertView pressed OK. But I couldn't do it. Here is my code;
{
UIAlertView alert = new UIAlertView();
alert.Title = "Warning";
alert.AddButton("OK");
alert.Message = "Payment not found!";
alert.Clicked += ButtonClicked;
alert.Show();
return paymentList;
}
private void ButtonClicked(object sender, UIButtonEventArgs e)
{
//???
}
Thanks.
First of all, Xamarin.Forms doesn't have UIAlertView class (Inside the PCL project).
You can display alert there by calling asynchronous DisplayAlert method inside the Page instance. For example:
public class PaymentPage
{
...
async void OnNoPaymentMethodDetected(object sender, EventArgs e)
{
await DisplayAlert("Error", "You have no payment method registered", "Okay");
await Navigation.PopAsync(true);
}
...
}
Note: your Pop Navigation method depends on your Push Navigation method. For instance, if you've used PushModalAsync(page2), then you have to use PopModalAsync() in page2 to move back, otherwise PopAsync() will cause an error.
If you want to have similar alert in iOS-specific project, you have to use the next code:
var controller = UIAlertController.Create("Error", "No payment method detected", UIAlertControllerStyle.Alert);
controller.AddAction(UIAlertAction.Create("Okay", UIAlertActionStyle.Cancel, (sender) =>
{
NavigationController.PopViewController(true);
}));
ShowDetailViewController(controller, null);
UIAleartView does not have specific events for Buttons.
But, you can access the index of the button pressed from the UIButtonEventArgs (ex: e.ButtonIndex) verify what button is pressed
I have login page based on MVVM and I try to call this.focus before I do proper login but the problem is that I have to click twice. First one just hide keyboard and give me information about missing username/password.
So probably the problem is connected with mvvm thing as fields are not updated when user clicks application bar button first.
I am new in MVVM so how can I do focus on page using it?
At the end, I did it without MVVM. My application bar button handler below.
void Set_Details_MenuItem_Click(object sender, EventArgs e)
{
object focusObj = FocusManager.GetFocusedElement();
if (focusObj != null && (focusObj is PasswordBox || focusObj is TextBox))
{
if (focusObj is PasswordBox)
{
var binding = (focusObj as PasswordBox).GetBindingExpression(PasswordBox.PasswordProperty);
binding.UpdateSource();
viewModel.Login();
}
else if (focusObj is TextBox)
{
var binding2 = (focusObj as TextBox).GetBindingExpression(TextBox.TextProperty);
binding2.UpdateSource();
viewModel.Login();
}
}
else
{
viewModel.Login();
}
}
I am working on an app on wp7.
I hope to prompt a confirmation dialog when user exit app (press back button).
Is it possible?
Welcome any comment
Please handle the BackKeyPress button in the Application page to handle the back key press.
In Page.xaml file in the element add this code
BackKeyPress="PhoneApplicationPage_BackKeyPress"
it should look like
<phone:PhoneApplicationPage BackKeyPress="PhoneApplicationPage_BackKeyPress"
..//other attributes .. >
in event handler you write the code as follows
private void PhoneApplicationPage_BackKeyPress(object sender, System.ComponentModel.CancelEventArgs e)
{
MessageBoxResult mb = MessageBox.Show("You want exit the page", "Alert", MessageBoxButton.OKCancel);
if( mb != MessageBoxResult.OK)
{
e.Cancel = true;
}
}
It's possible to catch when the user exits pressing the Back button, but it is not possible to stop the application from being made "dormant" when the user presses the hardware Start button or Search buttons.
You can stop back navigation by set e.Cancel in back key press event.
In MainPage.xaml.cs constructor:
OnBackKeyPress += (s, e) =>
{
if (MessageBox.Show("", "", MessageBoxButtons.OkCancel) == MessageBoxButtons.Cancel)
{
e.Cancel = true;
};
};