winrt backspace in Settingsflyout - windows-runtime

I create simple SettingsFlyout panel following this example of microsoft http://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh872190.aspx
Everything is fine, but how can I make backspace go back to settings panel?

You can doing what you want if you edit the control. Use Blend will help you so much. Right Click => Edit Template.

This work for me:
In code behind
private void settingsAbout_KeyDown(object sender, KeyRoutedEventArgs e)
{
if (e.Key == VirtualKey.Back)
{
SettingsPane.Show();
}
}
in xaml
KeyDown="settingsAbout_KeyDown"

Related

How can you prevent a ContentDialog from closing on button press in WP8

In Windows Phone 8 (or 8.1), is there a way to prevent a ContentDialog from closing when the primary button is pressed under certain conditions? For example, say you have a Boolean done. When they click the primary button, I only want the ContentDialog to close if (done == true). Is this possible?
XAML:
<ContentDialog
...
Closing="ContentDialog_Closing">
C#:
private async void ContentDialog_Closing(ContentDialog sender, ContentDialogClosingEventArgs args)
{
if (!CanClose)
args.Cancel = true;
}

How do I remove focus from a button, so that pushing the spacebar or Enter doesn't trigger the button?

When you click or tap a button, it gives it focus, so that when you push the spacebar or Enter, it triggers the button again. I don't want that to happen.
I tried this: button1.Focus(Windows.UI.Xaml.FocusState.Unfocused);
But the unwanted behavior still happens (pushing the spacebar or Enter triggers the button again). I also tried setting focus to another button using the Programmatic and Keyboard FocusStates but that doesn't fix it either.
Any help, especially an explanation of why this is happening, would be greatly appreciated.
You can set the TabStop property to False, but be aware that doing this disallows user from using the button by keyboard.
<Button Content="Click Me By Pointer!" IsTabStop="False"/>
Update
As msdn states:
You can't remove focus from a control by calling this method with FocusState.Unfocused as the parameter. This value is not allowed and causes an exception. To remove focus from a control, set focus to a different control.
So another way to achieve this, is setting focus to previously focused element when the button is about to get focus by pointer. Unfortunatly the GettingFocus event is not working for the Button class (maybe because final version is not released yet?) so we should use GotFocus event, it's ugly it but works.
bool moveFocus = false;
public MainPage() {
this.InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e) {
if (moveFocus) {
UIElement focusedElement = FocusManager.FindNextFocusableElement(FocusNavigationDirection.Right);
if (focusedElement is Control) {
((Control)focusedElement).Focus(FocusState.Programmatic);
}
}
}
private void Button_GotFocus(object sender, RoutedEventArgs e) {
Button button = (Button)sender;
moveFocus = (button.FocusState == FocusState.Pointer);
}
Note that I passed FocusNavigationDirection.Right to FocusManager.FindNextFocusableElement to get an element in right, I should have used FocusNavigationDirection.Previous instead to get previous element but it returns null for unknown reason.

Windows phone 8.1 BackPressed not working properly

Windows phone 8.1 new to world. Basic function is back button click. Is that function not working properly is this windows phone 8.1. Is that behavior or i'm made mistake.
Below code using in Homepage but this code calling from all other class too while clicking back. I need to access below method only on Home page .
Please check below code and refer me good solution.
Please look my code:
public HomePage()
{
this.InitializeComponent();
Windows.Phone.UI.Input.HardwareButtons.BackPressed += HardwareButtons_BackPressed;
}
void HardwareButtons_BackPressed(object sender, BackPressedEventArgs e)
{
}
Thanks
It is working properly. The BackPressed event is working app-wide. Two options that come to my mind:
write eventhandler that would recognize the Page in which you currently invoke it - simple example can look like this:
private void HardwareButtons_BackPressed(object sender, Windows.Phone.UI.Input.BackPressedEventArgs e)
{
Frame frame = Window.Current.Content as Frame;
if (frame == null) return;
if (frame.Content is HomePage)
{
e.Handled = true;
Debug.WriteLine("I'm in HomePage");
}
else if (frame.CanGoBack)
{
frame.GoBack();
e.Handled = true;
}
}
second option - subscribe to Windows.Phone.UI.Input.HardwareButtons.BackPressed when you enter the Page and unsubscribe when you leave the Page. Note that in this way there are some pitfalls - you have to handle properly OnNavigatedTo, OnNavigatedFrom, Suspending and Resuming (more about Lifecycle here). Note also that the subscription should be done before others - for example NavigationHelper.
Some remarks - the above code should work, but it also depends on other circumstances:
if there is something other subscribed to BackPressed before (in App.xaml.cs) - remember that usually events are fired in order they were subscribed
check if you are using NavigationHelper - it also subscribes to BackPressed
remember not to subscribe multiple times
remember to allow the User to leave your HomePage

Windows Phone 8 Accelerometer

I'm trying to use the Accelerometer in my application but an error comes up and I have been trying to get around it. I'm not the best programmer but I'm trying to get better. the error is "accelerometer_CurrentValueChanged doesn't exist". How do I use this properly, many sites use this line of code and I'm wondering why it isn't working for me. I have all the API and I have the references that I am meant to have but it just wont work. What is it even there for? any help would be much appreciated
If you have this in your output view, you need to check in your .cs, if you have this methode.If you don't have this, you need to choice to delete property in your xaml or put the correct methode in your .cs.
Like this =>
void accelerometer_CurrentValueChanged(object sender, SensorReadingEventArgs<AccelerometerReading> e)
{
//Do your job
}
But please use your favorite web browser for do a little search before post in stackoverflow.
Accelerometer accelerometer;
public AccelerometerTest(){
accelerometer = new Accelerometer();
if (accelerometer != null)
{
accelerometer.CurrentValueChanged += accelerometer_CurrentValueChanged;
accelerometer.TimeBetweenUpdates = TimeSpan.FromMilliseconds(1);
accelerometer.Start();
}
}
void accelerometer_CurrentValueChanged(object sender, SensorReadingEventArgs<AccelerometerReading> e)
{
//do your code
}

Keyboard overlaps popup in wp8

I am developing a Login screen in which the user needs to introduce their data and then submit them.
Considerations which I had: I have thought about using a Page, but eventually I rejected the idea because if I put Login page before the MainPage, then if I go back from MainPage, then it would go to Login page, which is not what I want. And if Login page were after MainPage, then if I execute for instance the app for first time, without being logged in, if I press back, then it would go to MainPage which I don't want as well.
The problem: I decided finally to use a Popup. At the moment looks perfect, but when I want to use a textbox, the Keyboard overlaps that textbox, and what I want is to move the Popup upwards just like a normal page. I don't know if is that possible, otherwise I am willing to hear some alternatives.
Thank you in advance.
In WMAppManifest.xml remove the property of Navigation Page and in you App.xaml.cs you have something like:
private void Application_Launching(object sender, LaunchingEventArgs e)
{
LoadDefautPage();
}
void LoadDefautPage()
{
if (StartForFirstTime)//tombstone local variable
{
if (!IsLoggedIn)//flag save it in IsolatedStorageSettings
{
RootFrame.Navigate(new Uri("/LoginPage.xaml", UriKind.Relative));
}
else
{
RootFrame.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
}
StartForFirstTime = false;
}
}
finally remove Back Entry in MainPage:
protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
{
while (this.NavigationService.CanGoBack)
{
this.NavigationService.RemoveBackEntry();
}
}
It's just an idea, let me know how it goes (: