Overriding <Enter> key behaviour in Windows Phone 7.1 - windows-phone-7

I'm developing an app for Windows Phone 7.1. I was wondering if it is possible to override the behaviour of the enter button on the virtual keyboard. Basically, I want the user to be able to submit the form if he/she presses the enter button when filling the last field of the form. Please let me know if it is possible or if the convention is not to do so.
Thanks.

There is event OnKeyDown for this purpose
textblock.OnKeyDown += (s, e) =>
{
if (e.Key = Key.Enter)
{
//do your stuff here
}
};

Related

Prompts on top of popup windows in Xamarin and MAUI

I have discovered the limitation of displaying prompts when they are invoked from a popup window. Specifically verified with CommunityToolkit.Maui Popups.
Here's the details:
In the Map page I have this handler for the map clicked event:
void mapClicked(object sender, MapClickedEventArgs e) {
var pin = new Pin {
Label = "Here's where it is",
Location = e.Location
};
map.Pins.Add(pin);
}
I wanted to allow the user to edit the pin label when clicking on the it, like so:
pin.InfoWindowClicked += async (s, args) => {
string pinName = ((Pin)s).Label;
await DisplayPromptAsync("Enter new label", "enter new label");
};
However, this didn't work as no DisplayPrompt was shown. I tried running it in the main thread, to no avail either.
UPDATE. I've figured it out, see answer below.
The problem arises when attempting to bring up the prompt from a popup window. Evidently, one can't have a DisplayPromptAsync (or DisplayAlert for that matter) on top of a popup.
On a platform-specific level in iOS the error message reads:
Attempt to present <UIAlertController> on <Microsoft_Maui_Controls_Platform_Compatibility_ShellFlyoutRenderer> (from <Microsoft_Maui_Controls_Platform_Compatibility_ShellFlyoutRenderer>) which is already presenting <CommunityToolkit_Maui_Core_Views_MauiPopup>.

Windows Phone 7 Back Key Press event change?

I want to do some work if user presses back key on the phone with navigating back How to do it?
With following code it cancel navigation to back page & do some stuff but i want to do stuff while going back please help...
protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
{
// do some stuff...
e.Cancel = true;
}

WP7 PhoneGap application back button exiting application

I am working on WP7 Phonegap app. I have used below code to handle back button, but whenever I click back button , back button event is not cancelled and application gets exited.
void OnBackKeyPressed(object sender, CancelEventArgs e)
{
var result = MessageBox.Show("Dof fd fd you want to exit?", "Attention!",
MessageBoxButton.OKCancel);
if (result == MessageBoxResult.OK)
{
// Do not cancel navigation
return;
}
e.Cancel = true;
}
Please helpme on same.
Thanks in advance.
One of the lead devs for the Windows Phone implementation of PhoneGap recently wrote about correctly handling the back button.
See his article at http://www.risingj.com/archives/493

How to Disable Windows Phone 8 Keyboard buttons?

I'm working on windows phone 8 textBox where i just change the inputscope of the textbox to number/digits. Problem is there is no use of dot(decimal point) button in the textbox so i want to disable the dot button or when user click on that button it does not reflect in the textbox i need to input only numbers. So Please help me in this Problem as i'm beginner. Thanks a lot.
You can just attach to the TextBox.KeyDown event and set it to Handled = true when a . is inputed, like this:
private void MyTextBox_OnKeyDown(object sender, KeyEventArgs e)
{
if (e.PlatformKeyCode == 190)
{
e.Handled = true;
}
}
The code for . is 190

How can I tell when the "search" button is clicked when I set InputScope to search?

For Windows Phone. How can I tell when the "search" button is clicked when I set InputScope to search on a TextBox? Is there an event?
When the InputScope is set to "Search", the "search" button is just a restyled "enter" button. So, assuming:
<TextBox InputScope="Search" KeyDown="SearchBox_KeyDown" />
the "search " button being pressed (on the SIP) can be detected with:
private void SearchBox_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter)
{
// Do search...
}
}
In addition to what Matt has (correctly) answered, if you handle e.PlatformKeyCode == 0x0A (as shown below) you can also respond to the Enter key being pressed on the host keyboard when running in the emulator without the SIP.
if ((Key.Enter == e.Key) || (e.PlatformKeyCode == 0x0A))
{
// Do search...
}
Do you mean the hardware search button? It's not exposed.
Similar question
For Windows Phone 8.1 Apps (not Silverlight) you may use VirtualKey
if (e.Key == Windows.System.VirtualKey.Enter)
{
//Do Something.
}

Resources