Source Code in C# When Lock screen button pressed windows phone app will close. and also close when start button press?
for this purpose
in App.xaml.cs,
private void Application_Deactivated(object sender, DeactivatedEventArgs e)
{
Application.Current.Terminate();
}
Related
I want to know from which page navigated to a given page by pressing the back button. But I didn't find a solution for it in WP8.1
Parameters can be used for forwards navigation, as I know.
Can anyone help me?
You want to know which page was displayed before the user navigated back to your current page? You can inspect Frame.ForwardStack for that:
protected override void OnNavigatedTo(NavigationEventArgs e)
{
if (e.NavigationMode == NavigationMode.Back)
{
// get the type of the page that was shown previously
var navigatedFromPage = Frame.ForwardStack[0].SourcePageType;
}
}
Is it possible to change a Hubsection as if you moved it with your finger per code? E.g. I have three HubSections, I click a button in HubSection3 and it changes to HubSection1.
If you assign both your hub and your sections names, then in your code-behind you can do something like this:
private void Button_Click(object sender, RoutedEventArgs e)
{
MyHub.ScrollToSection(HubSection1);
}
However from a UI perspective, I personally wouldn't drive the navigation with a button in this way. As generally, the purpose of a hub is to display content in a similar style to that of a magazine, allowing the user to flick through the content at their discretion.
I have a global page that hosts navigation buttons to diffeernt pages. it also hosts a frame called ContentFrame. It navigates to the diffeernt pages as the navigation buttons are clicked. But initially some calls are made to the DB and when data is returned, the ContentFrame navigates to the mainpage first.
I have a back button and a home button. When the contentframe has MainPage in it and the back button is clicked, I want the app to go back to a previous page from which this whole global page is loaded. If the content frame just has some other pages loaded, then I want it to simply go back to the previous page that was loaded when back button is clicked.
Here is my code for the contentframe in the global xaml
<Frame x:Name="ContentFrame" Grid.Row="1" Grid.Column="1" />
Here is my back button click code for global page
private void Back_Click(object sender, RoutedEventArgs e)
{
if ((ContentFrame.CurrentSourcePageType != null) && (ContentFrame.CurrentSourcePageType.Name.Equals("MainPage")) && (this.navigationHelper.CanGoBack()))
{
ResetPageCache();
this.navigationHelper.GoBack();
}
else
{
if (this.ContentFrame.CanGoBack)
{
this.ContentFrame.GoBack();
}
else if (this.navigationHelper.CanGoBack())
{
this.navigationHelper.GoBack();
}
}
}
private void ResetPageCache()
{
var cacheSize = (this.Frame).CacheSize;
(this.Frame).CacheSize = 0;
}
The issue that I am facing is that when the ContentFrame has main page loaded and back button is clicked, it navigates back to a previous page before the global page was loaded but in the process, the onnavigatedfrom() event for MainPage is not raised where I unsubscribe some events.
Any idea how I can get the onNavigatedFrom() to fire for MainPage in this case?
Thanks
The simplest solution might be to handle the Unloaded event apart from/instead of OnNavigatedFrom so that your clean up happens regardless of navigation but rather when just being removed from the visual tree. You might want to pair it with the Loaded event though in case your page gets added to the visual tree without being navigated to (e.g. when the cached parent page is being navigated to).
Sure. Do this:
var frame = Window.Current.Content as Frame;
frame.SetNavigationState(string.Empty);
Best of luck!
i have created a windows phone application. In each page i have given a back button using "NavigationService.GoBack()" command. i want that when the back button is pressed the previous page to which it navigate the whole code of that page must again be executed.
If you're relying the user pressing the hardware back button you shouldn't have to call GoBack() yourself.
To refresh a page when the user navigates back to it you can use the following in your page (and add the refresh code as appropriate):
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
if (e.NavigationMode == NavigationMode.Back)
{
// Do your refreshing here
}
}
I have created a JDialog to be opened when I click on the edit button of my JFrame, it is being opened properly and does'nt have any issue, but when I took this code on the windows ce 5.0 device this dialog is being opened twice. hat is i am clicking only once on the edit button but the dialog is appearing twice, I want there should be only one dialog appear on edit button click.
ok I have got the solution
public void valueChanged(ListSelectionEvent e) {
if (e.getValueIsAdjusting() == false) {
List lsm = (List) e.getSource();
showDialog();
lsm.clearSelection();
}
}