How to enable PhoneApplicationPage_BackKeyPress event when set textbox.Focus() on textbox_LostFocus event in windows phone 8 - windows-phone-7

How to enable
PhoneApplicationPage_BackKeyPress
event when set textbox.Focus() on textbox_LostFocus event in windows phone 8.
I want to show keyboard when i add some item into listbox from textbox. Listbox gets update but my keyboard always gets hide on button click.
I want to make it open all the time till i press back key.
Thanks,
Nishant

you can get BackKeyPress Event by :
protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
{
base.OnBackKeyPress(e);
}
You can write textbox.Focus() at the end of button click when all work is done
try this :
private void btnAdd_Click(object sender, RoutedEventArgs e)
{
ListboxName.Items.Add(TextBoxName.Text);
TextBoxName.Text = "";
TextBoxName.Focus();
}
I have implemented. Its working...

Related

Xamarin DataPicker how to handle done button click event

I added to my DataPicker unfocused event. And in this event I would like to check if Done button was clicked.
private void DatePicker_Unfocused(object sender, FocusEventArgs e)
{
}
Or other option.
Is it possible to add listener to button Done, and if was clicked then fired some method?
How can I do it?
Thank you.
Every UI control which receives input always has some event handlers which you can listen to.
In your case the DatePicker has an Event Handler which fires when the Date property changes.
Here is the documentation:
DatePicker Event Handler - Xamarin Documentation
The implementation of this handler is simple:
DatePicker datePicker;
DateTime newDate;
DateTime oldDate;
public YourPage()
{
datePicker.DateSelected += Date_DateSelected;
}
void Date_DateSelected(object sender, DateChangedEventArgs e)
{
newDate = e.NewDate;
oldDate = e.OldDate;
}
Always read the documentation first, as that's the best way to learn how to use a specific control.

Xaml Button is "clicked" if it's pressed-and-hold on a touch screen

I am developing a Windows UWP App with C++. I want to add a button that can either be left-clicked or right-clicked and do corresponding task.
The button works perfectly on normal devices with mouse. Unfortunately on touch screen, if users press-and-hold the button, both left-click and right-click events are triggered.
I am using "Click" to handle the left click event and "RightTapped" to handle the right click event. Any suggestion on how to disable the left-click event when users press-and-hold the button? Thank you!
The XAML code is short:
<Button x:Name="m_NewPageButton"
Content="New Page"
Height="48"
Width="199"
Click="OnClick"
RightTapped="OnRightClick"/>
And here's the cpp code:
void MainPage::OnClick()
{
// Left click task
}
void MainPage::OnRightClick()
{
// Right click task
}
Edit:
Thanks guys, the solution is to change the left click handler to , which will not be triggered by press-and-hold.
Hacky but works...
private bool rightClicked;
private async void Button_Click(object sender, RoutedEventArgs e)
{
if (rightClicked)
return;
await new MessageDialog("left").ShowAsync();
}
private async void Button_RightTapped(object sender, RightTappedRoutedEventArgs e)
{
rightClicked = true;
await new MessageDialog("right").ShowAsync();
rightClicked = false;
}
I'm guessing this is a flaw in the design.. :(
Actually... If you use the button's Tapped and RightTapped events it works as it should. So in this case just replace Clicked with Tapped and all is well... Then you can ignore the hack I put above.
You can use the Holding event to detect a tap and hold. Use the Tapped event for a single tap (or click). The Tapped event should only fire for touch on a quick tap and release. The mouse specific click will raise Tapped but a touch tap-and-hold will not.

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;
}

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

Windows phone 7 Handling backspace KeyDown event

I have a textbox in XAML:
<TextBox Text="blah"
Name="blah"
LostFocus="blah_OnLostFocus"
KeyDown="blah_OnKeyDown"/>
.cs file has the following event declared:
private void blah_OnKeyDown(object sender, KeyEventArgs e)
{
TextBox t = sender as TextBox;
int i = 0;
if(e.Key == Key.Delete)
i = 1;
}
When I press the backspace key on the emulator's keyboard, the event is ignored. If I press any other button, it is triggered. Also, when I use the same event body for the KeyUp event, backspace key triggers it.
How do I track when the backspace key was pressed for KeyDown event? Why is pressing the backspace key does not trigger the KeyDown event?
Thank you.
The backspace button is handled internally by the textbox control. The control will take the backspace event and remove a letter and won't bubble up the event to your event. This is by design. You'll notice that if there are no letters in the textbox, then the event is bubbled up. In order to get around this, you can use AddHandler to handle the event. Try doing this:
//Handle the mainpage loaded event and add the handler to the textbox
void MainPage_Loaded(object sender, RoutedEventArgs e)
{
textBox1.AddHandler(TextBox.KeyDownEvent, new KeyEventHandler(blah_KeyDown), true);
}
Then change your Key_Down event handler to this:
private void blah_OnKeyDown(object sender, KeyEventArgs e)
{
TextBox t = sender as TextBox;
int i = 0;
if(e.Key == Key.Back)
i = 1;
}
That should have the textbox internally handle the event, but also call your OnKeyDown event.
To detect backspace, you need to use Key.Back rather than Key.Delete
See Key enumeration at http://msdn.microsoft.com/en-us/library/system.windows.input.key(v=VS.95).aspx

Resources