When the user will click the "OK" button on the MessageBox below, something will happen for example, it will clear out the searchResult string and set it to "". Just to clarify, a message box will open up and show some string message (searchResult), but as soon as the user clicks on "OK" on that message box, searchResult will be set to "". How can I achieve this? How to create an event handler for this particular message box's OK button?
if (searchResult != "")
{
MessageBox.Show(searchResult);
}
There is no need for a listener. Just set searchResult to an empty string right after calling MessageBox.Show:
if (searchResult != "")
{
MessageBox.Show(searchResult);
searchResult = "";
}
You can use this if you are interested :)
http://msdn.microsoft.com/en-AU/library/system.componentmodel.backgroundworker.runworkercompleted.aspx
Related
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 want to give the privilage for the user to rename a file. For that When the user clicks on menu item 'rename'a pop up dialogue with and editable text box should show up with 'ok' and 'cancel' buttons? How can i implement it? Pls share the code if there are any.
Br,
Jinu
You can use the InputPrompt from the Coding4fun Tookit
The documentation is available on Codeplex: http://coding4fun.codeplex.com/wikipage?title=InputPrompt&referringTitle=Documentation
Calling it is straightforward:
var input = new InputPrompt();
input.Completed += InputCompleted;
input.Title = "Rename file";
input.Message = "Enter a new name for the file:";
input.Show();
Then you just have to retrieve the value in the callback:
private void InputCompleted(object sender, PopUpEventArgs<object, PopUpResult> e)
{
MessageBox.Show(e.Result);
}
View:
TextBox x:Name="feedback" Text="{Binding FeedbackText,Mode=TwoWay}"
ViewModel:
public string FeedbackText
{
get
{
return _feedbackTextProperty;
}
set
{
_feedbackTextProperty = value;
RaisePropertyChanged(FeedbackTextPropertyName);
}
}
I am using a bindable application bar but when I click the button there is no value in the FeedbackText property. It looks as if "lostfocus" is not firing to update the property.
I am using MVVM Light. Have I missed something?
If you still had focus in the textbox when you clicked the app bar button the textbox won't fire the lost focus event and cause teh binding to update.
Yes, this can be frustrating. :(
There are various work arounds such as forcibly updating the binding in such a situation or the Binding Helper in the Coding4Fun Tools.
I hope that I am not too late. I had the same problem using Window Phone 8 saving the TextBox text when pressing an ApplicationBarIconButton. A way to fix this issue is to update the binding source property of the focused TextBox. You can do that with the following code:
var focusedObject = FocusManager.GetFocusedElement() as TextBox;
if (focusedObject != null)
{
var binding = focusedObject.GetBindingExpression(TextBox.TextProperty);
if (binding != null)
{
binding.UpdateSource();
}
}
Best!
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;
};
};
I need show a simple dialog with the question : 'Do you want to exit the application?' YES or NO.
This dialog will be shown when the user presses the back button of the device.
I know how I can show this dialog , but I don't know how to disable the back action: close app.
It's always closed.
If I understand you correctly, you want to display a confirmation dialog when the user clicks the back button on the main page of your app to ask whether they really want to exit. If the user selects Yes the app exits, otherwise you cancel the back navigation. To do this, in the MainPage class constructor hook up an event handler
MainPage()
{
BackKeyPress += OnBackKeyPressed;
}
void OnBackKeyPressed( object sender, CancelEventArgs e )
{
var result = MessageBox.Show( "Do you want to exit?", "Attention!",
MessageBoxButton.OKCancel );
if( result == MessageBoxResult.OK ) {
// Do not cancel navigation
return;
}
e.Cancel = true;
}