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.
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;
}
}
I have a viewpager which utilizes the native actionbar Tabs as the indicator. I would like to navigate to different tabs, but Tab component is not a view therefore, onView, or withText does not work properly with perform clicks.
Is there a specific way I can do to navigate through the Tab navigation?
You could use swiping to navigate between your tabs:
onView(withId(R.id.viewpager)).perform(swipeLeft());
onView(withId(R.id.viewpager)).perform(swipeRight());
Assuming there is text on the tab, you can do:
onView(withText("Tab Text")).perform(click())
onView, withText and click are static imports.
I created the following method to select any tab with the text on view.
public MainScreen clickOnTab(String tabText) {
onView(allOf(withClassName(endsWith("TabView")),
withChild(withText(tabText)),
withParent(withParent(withId(R.id.main_activity_tab_layout)))
)).perform(scrollTo()).perform(click());
return this;
}
and in order to call this method simply call the method like below:
MainScreen.getInstance().clickOnTab("Tab Name");
Cheers
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.
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 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?