Windows Phone 8 : Prevent a PhoneApplicationPage from being added to backstack - windows-phone-8

I have a phone page which navigates to another. Is there a way to prevent the fist page from getting into the backstack when navigating to the second?
I'd rather not remove the first page from the backstack in the code for the second page.

The most obvious way kind of works:
NavigationService.Navigate(new Uri(...));
NavigationService.RemoveBackEntry();
But it may fail - see submision problems described here.
If you were to remove the BackStack Entry on the second page (and thus disperse the knowledge of the first page behaviour in context of navigation), you would to that in OnNavigatedTo, which occurs after the navigation is completed and the entry is placed on the BackStack. PhoneApplicationPage similarly has OnNavigatedFrom method, which is also called after the navigation is completed (OnNavigatingFrom is called before navigation and allows cancelling). So first page could remove itself in the following way:
protected override void OnNavigatedFrom(NavigationEventArgs e)
{
NavigationService.RemoveBackEntry();
}
However, this method is incomplete, as OnNavigatedFrom is called not only after a succesfull Navigate, but also after pressing any of the three device buttons or showing a Launcher or Chooser (from Microsoft.Phone.Task). In those cases current page will not be placed on the BackStack (I guess that's why the BackStack corrections are applied usually on other Pages). So to fix the above method you could check if the last entry is what it should be:
protected override void OnNavigatedFrom(System.Windows.Navigation.NavigationEventArgs e)
{
var entry = NavigationService.BackStack.FirstOrDefault();
if (entry != null && entry.Source.OriginalString.Contains(...))
{
NavigationService.RemoveBackEntry();
}
}

I have the same requirement when implementing a login page. Upon navigation to the authenticated area of the app, I want to remove the login page from the backstack.
To do this, I simply pop the stack after the call for the navigation out of the login view.
NavigationService.Navigate("/Page2.xaml");
NavigationService.RemoveBackEntry();
This doesn't require code in your Page2.xaml.

No, there is no way. Why won't you remove it if you don't want it to be there?

Related

Appmaker: Handle several copies of a page fragment as one?

I have a SideMenu page fragment in my app. On each and every page, I have a copy of this page fragment.
My intention was to create a SideMenu with openable SubMenus (only one sub menu could be open at a time), but I could not get it done to make the app "remember" the state of the SideMenu( like which SubMenu should be open, and which ones shouldn't), because on each site there is a different widget, so when in my code ( in my onClick events) I refer to the widget, I am not handling "a global SideMenu" but rather a specific copy of it, unique to that page.
Sadly, this took several hours of debugging to realize, I am defeated.
Is there anyway to place a page fragment on a page, so I can handle that widget on its own, not just it's copies?
Thanks in advance, I can try to specify more the question if it's needed.
I agree with #MarkusMalessa. You need to invoke the widget on every page and then apply whatever change on it. I am doing the samething on a project in which I intend to shrink and expand the sideMenu. To give you an idea, evertime I click a button on the side menu responsible for the logic, this is the code that's invoked:
var pages = app.pages._values;
pages.forEach(function(page){
var sideMenu = page.descendants.sideMenu1;
if(sideMenu){
if(widget.text === "chevron_right"){
sideMenu.getElement().style.width = "300px";
} else {
sideMenu.getElement().style.width = "60px";
}
}
});
That way every sideMenu widget inside each page that has it receive the same changes.

How to prevent game controller button B from quitting app / navigating back to menu in tvOS

The game controller button B is, by default, quitting the app and navigating back to the tvOS home screen. At first I thought this was intuitive, but quickly realized that's what the Nimbus MENU button (dead middle of the controller) is for, and that I actually want to use button B in-game.
Setting a change handler for button B works, but the app still quits when the button is released.
GCControllerButtonValueChangedHandler buttonBHandler = ^(GCControllerButtonInput *button, float value, BOOL pressed) {
NSLog(#"B");
};
I had the same issue.
The solution was to have my main ViewController inherit from GCEventViewController instead of UIViewController.
By default, when using GCEventViewController, the MENU button will not return to the menu. In this case, if you want it to be able to return to the menu with the original behavior you can simply set controllerUserInteractionEnabled to YES.
see the documentation for this class here :
https://developer.apple.com/library/tvos/documentation/GameController/Reference/GCEventViewController_Ref/index.html
edit : apple dev forum helpep me fix this issue : https://forums.developer.apple.com/message/57926#57926
hope this helps,
I too had the issue, related to Unity, but I think this rather hacky solution can help.
Deriving from GCEventViewController one can override several methods, one of them is:
- (void)pressesBegan:(NSSet<UIPress *> *)presses withEvent:(UIPressesEvent *)event
returning or handling presses without calling super removes all calls to the internals.

asp:button reloads the page instead of firing OnClick event in Sitecore

I am using Sitecore and I have a header sublayout that I use in all pages. This layout contains a Logout button that fires OnClick event when clicked and executes the onclick event function. But in few pages it wont fire OnClick event at all instead it reloads the page.
Below is the code for the logout button
<asp:button id="btnLogout" runat="server" borderstyle="None" onclick="btnLogout_Click" text="Log out" ToolTip="Log out" backcolor="Transparent" style="cursor:pointer" class="logout_new"></asp:button>
Below is the code for the event function
protected void btnLogout_Click(object sender, EventArgs e)
{
Sitecore.Security.Authentication.AuthenticationManager.Logout();
Response.Redirect("/Login.aspx");
}
I found out that the difference between the pages where the logout fires the onclick event and pages where it does'nt is that they use the same header sublayout containing the logout button but they use different content sublayout though.
Note: I have not applied Cache to any sublayout.
Can anyone help me with this?
From the given context I don’t know what is the issue but here is what I will do if I have issue like this.
As you said only on few pages it is not working, it could be the other controls on that particular page is causing the issue.
I will pick two pages which has less controls on the presentation layer. Say PageA is a working page and PageB is a non-working page. Then I compare PageA and PageB and remove all common controls, this should narrow down the number of the controls on the presentation layer. Now check again to see if Page B is working or not. If not, I will try to remove one control at a time on PageB untill it starts working. If you find by removing certain control and the page started working then you can look into the particular control and identify the issue.
I hope this helps.
try disabling the cache as it would return the html without triggering the back end code.
To do so, one option is going to the presentation detail of those pages, find the control and click on it to edit. Under the "Caching section" uncheck "Cacheable" and publish the item. If this fixes your problem, I'd review the standard values of the template, to apply the change to all the items with the same template
This behavior happens to me at annoying times too, but it's almost always the same thing: the Sitecore sublayout the code is in is being cached.
The onclick javascript fires, but the page is not re-rendered with new content because the "unclicked" version is stored in the cache.
You'll need to disable caching on the sublayout to make the button work.
This can, however, be somewhat annoying if you're trying to cache as much presentation stuff as you can. In those cases, it often means you need to, counter-intuitively, create a number of "sub-sublayouts" and place them statically. Set the containing sublayout to be uncached, and then you can set each smaller one's caching appropriately (caching static parts, not caching dynamic stuff).
The problem was in the content sublayout in which it was not working, the Page_Load function was calling a Response.Redirect function to itself and it was not checking if it was a post back request or not before that. So Whenever a user clicked logout button it used to post it back to the server and the page used to reload instead of executing the onclick event.
I noticed that in the other content sublayout where it was working, it was checking if it was a post back or not.
I added a if(!IsPostBack) before that and it started working.

Windows Phone disable back button when TimeSpanPicker has focus (i.e user choosing time span)

I am currently implementing a countdown timer for a windows phone app and I am having some trouble disabling the back button when the user is choosing a time span from the TimeSpanPicker. I only need to disable it when this is occurring and so it has to work fine apart from this.
I have the override OnBackKeyPress method with the following code inside it:
protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
{
if(//user choosing duration using TimeSpanPicker)
{
e.Cancel = true;
}
base.OnBackKeyPress(e);
}
As you can see from the commented pseudo condition, I need a way of checking if the user is currently choosing a time span duration and if so disable the back button.
Many thanks in advance!
Your app will be rejected from the market if you completely disable the back button.
There are a number of reasons for this but the main one is that we want a consistent user experience across the platform. That's a great thing we have going for us. A user should be able to open your app and expect the buttons to function as they expect.
One acceptable reason to override the back button is if you are on a game screen and you want the game to pause. Another reason would be if you had a custom menu appear and the back button hides the menu. Both of these scenarios are obvious to the user.

Navigate inside UserControl

I'm working on a application where I load a XAML page inside a usercontrol,
depending on which menu item was clicked.
After figuring out how to load in XAML page in a XAML page (using usercontrol), I'm running into the next problem: Navigation.
I added a picture to illustrate what I'm working on.
When you launch the app, you see the left state (state open), where the menu is presented and a little bit of the content on the right.
If you click the red button, the page scrolls to a "full screen" of the right state (state closed). This is still the same page, the MainPage.xaml, but with a new page loaded in the usercontrol. Let's say the loaded page is news, where you can select an article by clicking.
This all works great.
The problem is, when I try to use the navigationservice to see a detail of the news, the app fails. (it does work when I set the news page as start page, but it won't work inside the usercontrol).
I tried fixing this by the following code:
NewsDetail detailpage = new NewsDetail();
this.Content = detailpage;
Actually, this works.. but then I can no longer pass a querystring to load a certain article on the page.
Any ideas on how to fix this problem?
You can use a static variable in App.xaml.cs when querystrings become useless.
just declare a static variable of type say string in app.xaml.cs
public static string MyString;
just assign it a value before navigation
App.MyString="Hello";
And get this value where ever you want to get it.
string ss=App.MyString;