Navigating in Windows Phone App requires additional App - c#

I'm currently working on an Windows Phone App in Visual Studio for my Lumia 1520 with Windows Phone 10.
To navigate between the MainPage and the SecondPage, I use the code:
private void HyperlinkButton_Click(object sender, RoutedEventArgs e){
Frame.Navigate(typeof(SecondPage));
}
When clicking the Button in the App on my Phone, I receive the information, that:
The task requires an additional App. Would you like to search the store for it? (Yes/No)
When I hit "Yes" I get redirected to the Store, where I receive the information:
Your search for "ms-resource" had no results.
What kind of App is required by my phone? Is there another way to navigate between the pages without installing additional Apps?

The problem is that you have defined NavigateUri for your HyperLinkButton. Remove that attribute and the navigation to second page should work correctly.
In more detail, your code quite likely looks like this:
<HyperlinkButton NavigateUri="SecondPage.xaml" Click="ButtonBase_OnClick" Content="Hello"/>
And your code behind as you mentioned is this:
Frame.Navigate(typeof (SecondPage));
Now when you click the hyperlink, this happens:
But now if you remove the NavigateUri from your XAML:
<HyperlinkButton Click="ButtonBase_OnClick" Content="Hello"/>
The navigation works:
This behavior is somewhat vaguely described on MSDN:
HyperlinkButton is a control, so it has input events such as Tapped,
and it's a ButtonBase subclass so it also has a Click event. You don't
typically specify a value for NavigateUri and also handle input events
that are interpreted as clicking the HyperlinkButton. The action of
opening the NavigateUri in a default browser is a system action that
takes place without requiring any event handling.

Related

Accessing SplitView control from a different page than it's host - C# XAML Windows 10 UWP

Pre-warning, I'm new to C# and XAML, but I'm really enjoying Windows 10 UWP apps. I've got a question on how to appropriately handle a SplitView.
I've got a Main Page, in which I have a SplitView control. In the SplitView Content, I've added a Frame for navigation to other pages. I want to add the Hamburger button on the child page to open the SplitView on the Main Page, but I can't access the SplitView control from the child page. How can I make the SplitView control accessible so that the hamburger button within the sub-page can open the SplitView pane?
The alternative is to add a header in the Main Page and have a static hamburger button there, but I don't like this option as it makes handling the text header content more difficult. Another is to copy the SplitView to each page. I don't want to do this either.
Any advice would be fantastic! Thank you.
I would highly recommend you take your alternative option of including the hamburger button in the main page. Users always expect it to be in the same location every time and changing this approach will probably result in a bad user experience.
You also don't want to be repeating code and thus you don't want to recreate the button on every page as well as any additional functionality like the open/close commands.
Rather than referencing elements from one page to another, a better practice is to keep things loosely coupled. This can be done with a messenger plugin which sends an event from one page to the other which can give it instructions on what you want to do. That way the other page only has to listen for the event instead of holding strong references. To streamline some of this process you could inherit from a base class which implements the messenger functionality.
That would provide a solution to your button and your header text situations but setting them up is out of the scope of this question. Depending on the size of you app and your goals, you might like to look into existing frameworks which helps in designing maintainable apps. A good Mvvm framework I would recommend checking out is MvvmCross which also cross platform and contains a messenger plugin.
Good luck with your app.
I found that solution :
In the MainPage, in your SplitView pane button method, add a SplitView reference as parameter in Navigate() :
private void SlitViewPaneButton_Tapped(object sender, TappedRoutedEventArgs e)
{
var frame = contentFrame;
Page page = frame?.Content as Page;
if (page?.GetType() != typeof(ChildPage))
{
frame.Navigate(typeof(ChildPage), SplitViewName);
}
}
In your ChildPage.xaml.cs :
protected override void OnNavigatedTo(NavigationEventArgs e)
{
SplitView sv = new SplitView();
sv = e.Parameter as NavigateControls;
}
You can now do sv.IsPaneOpen = false, in your ChildFrame code.
Note : if you want to pass several Controls, create a Class with these Controls as variables, and use an instance as parameter.
As stated above, it is better to keep your hamburger button in your main page for a couple of reasons. One is the consistency mentioned above. Second, you would have to recreate the hamburger button in each of your content pages instead of just once in the MainPage.xaml. Additionally, keep in mind, there are different kinds of interactions with the SplitView menu in terms of how it pops in and out and how it is displayed, all listed below.
Inline – When the menu pane is opened, it pushes the content over. When it’s closed, the content goes back to its original location
Overlay – When the menu pane is opened, it lays on top of the content. When it’s closed, it is invisible.
Compact Overlay – When the menu pane is opened, it lays on top of the content. When it’s closed, the pane is still visible in Compact Mode.
Compact Inline – When the menu pane is opened, it pushes the content over. When it’s closed, the content goes back to its original position but the pane is still visible in Compact Mode.
You can also see a quick intro into the SplitView here.
http://jamesqquick.com/windows-10-splitview-intro/

SuspensionManager in Windows Universal Apps doesn't do anything on fast app switching

I'm having troubles understanding how can I execute code when doing fast app switching (i.e. pressing the Windows/Start button to show Start screen on the Phone emulator, and then pressing the Back button to go back into the app).
To simplify the issue, I started a new Windows Universal App that uses the "Visual C# Hub App (Universal Apps)" template as base code (since it includes the SuspensionManager and the NavigationHelper). Since I'm not interested in the Hub itself, I removed all the Grid content from the HubPage.xaml and simply added a TextBox called TimeTextBox:
...
<Grid x:Name="LayoutRoot">
<TextBox Name="TimeTextBox"/>
</Grid>
</Page>
Then, in the HubPage.xaml.cs, I added the following simple line to the method NavigationHelper_LoadState:
private async void NavigationHelper_LoadState(object sender, LoadStateEventArgs e)
{
var sampleDataGroups = await SampleDataSource.GetGroupsAsync();
this.DefaultViewModel["Groups"] = sampleDataGroups;
TimeTextBox.Text = DateTime.Now.TimeOfDay.ToString();
}
If I execute the app on the Phone emulator after applying those simple changes, the app will show the time of the day when loading the page, for example: 16:08:53.4390827.
What I want is that time to be updated every time I navigate to that page. But I if use the Lifecycle Events from Visual Studio to simulate a Suspend, when I send the Resume event the time is still the same: 16:08:53.4390827, and a breakpoint in that line will confirm that the NavigationHelper_LoadState method doesn't get executed when resuming.
The explanation for this is that the App.xaml.cs, as it is in the template, doesn't provide any listener for the Resume event, so nothing gets executed. Adding the next few lines fixes that:
public App()
{
this.InitializeComponent();
this.Suspending += this.OnSuspending;
this.Resuming += App_Resuming;
}
async void App_Resuming(object sender, object e)
{
await SuspensionManager.RestoreAsync();
}
So if I run again the app on the Phone emulator, now I get the actual time after resuming. Great! The problem is that these Suspend/Resume events don't get triggered when I simply tap on the Windows button of the Phone and then tap on the back button.
Actually, I haven't been able to identify one single method that gets executed when performing that kind of fast app switch. And that's the scenario I'm actually interested for my Universal App.
Is there a way of catching when the navigation brings us back into the app from the Start screen through the Back button? Am I missing any code to handle this scenario?
Thanks!
There's nothing wrong here. It's the default behavior. When you debug a Windows Phone 8.1 app from Visual Studio, the only way to trigger Suspend/Resume event is using the Lifecycle Events in VS. But when you run the app without VS, those methods will trigger as expected. :)

How to make a touchable notice top bar in windows phone?

How to make a touchable notice top bar in windows phone ?
I am new to C# and windows phone world.So may be my question has a simple
way to solve,but I google a lot ,and didn't work out.
here is my purpose: I have a timer running throughout my app,it request a
service for notice info every one hour, and show a "notice bar" on the top of
screen.
it is easy to get the information ,but when I want to show them to the Page,
here is my problem:
1.
I used system tray to show my info.
It works,but then I found there is no touch or click event for Progress
Indication bar.
I even add an event to Touch.FrameReported in App.xaml.cs , but still ,
when i touch the system tray area, the event doesn't fire.
2.
Then I want to use a Dynamic way to achieve it: add a text block to the
current page
I got the current page handler ,but case I only know the current page
handler's type is PhoneApplicationPage, I can't get my Root UI element
(all my page has a root element named "LayoutRoot")
And when I try to use reflect method to get the "LayoutRoot" property,
the return value is null.
The code looks like this :
Type type = PhoneApplicationPageHandler.getType()<
//I checked,the type is my page's type
type.getProperty("LayoutRoot") or type.getField("LayoutRoot")
//they all return null
BTW: LayoutRoot is a grid, and it is described in my page's .xmal file.
Now My option is to make all my page inherit a defalut page ,in this page ,I will
implement a method to fulfill my second way to simulate a "touchable top bar".
but I think this coding is ugly .
So, can anyone tell me :
1.how to add touch event to a SystemTray
or
2.how to get a handler of an ui element which is described in xaml, while I only have a PhoneApplicationPage type handler of that page.
You may use
1) a toast prompt described here http://windowsphonegeek.com/articles/WP7-Toast-Prompt-in-depth
2)or shell toast described here http://www.c-sharpcorner.com/UploadFile/ae35ca/working-with-toast-notification-in%C2%A0windows-phone-7/ according to what suits your requirement the best. 3)You may also create a custom control which you may place on the top on your mainPage and handle its tap event accordingly.

Adding hyperlink button in XAML with Visual Studio 11 (Windows 8)

I need to add a hyperlink button that directs to a webpage to my metro style apps written with C# and XAML. As in Silverlight, there is no NavigateURI option. Is there any other option to make a hyperlink redirect to a specific webpage?
There's a sample in the Sample App Pack that does this.
// Launch a URI.
private async void LaunchUriButton_Click(object sender, RoutedEventArgs e)
{
// Create the URI to launch from a string.
var uri = new Uri(uriToLaunch);
// Launch the URI.
bool success = await Windows.System.Launcher.LaunchUriAsync(uri);
if (success)
{
rootPage.NotifyUser("URI launched: " + uri.AbsoluteUri, NotifyType.StatusMessage);
}
else
{
rootPage.NotifyUser("URI launch failed.", NotifyType.ErrorMessage);
}
}
I don't know about Silverlight but in WPF (almost same as SL) we have TextBlock whose inline tag is Hyperlink.
<TextBlock>
Some text
<Hyperlink
NavigateUri="http://somesite.com"
RequestNavigate="Hyperlink_RequestNavigate">
some site
</Hyperlink>
some more text
</TextBlock>
U said "as in silverlight there is no NavigateURI option in this". No Problem.
i didn't knew about this feature of NavigateURI b4. so what i did was when the user clicked on that link it called the browser to open my requested link. In mouse over i changed cursor to look like hand and text color as red and on mouse leave back to default color (Blue) and cursor (Arrow).
I think u got my point.
I blogged about wiring up HyperlinkButton in Windows8 XAML to launch internet explorer
http://zubairahmed.net/?p=266
Windows.System.Launcher has methods to open the appropriate app for a given Uri or StorageFile. Just wire that up to the click event of your button
Just in case somebody stumbles upon this:
I'm using Visual Studio 2012 RTM on Windows 8 RTM and NavigateURI is back and opens the default metro browser.

How do you navigate to a new page in a metro app?

trying to write a metro app in C# right now. Ran into a problem while trying to navigate to a new page.
<HyperLinkButton NavigateUri="foo.xaml"/>
doesn't work, as the NavigateUri field doesn't exist.
The Windows.Navigate namespace isn't available either, so no luck there. What's the proper way to go to a new page in my app in metro?
You can handle the Button control's Click event (in fact, you can use all events with the following code) because Metro's HyperLink button only inherits the ButtonBase class without any special properties or events, such as NavigateUri.
If you want to navigate to another page in your metro app, add a frame in the .xaml page and put this code in the button's event handler:
this.Frame.Navigate("VideoStoryCreator.ComposePage");
There are two ways of Navigating to another page -
Client app way ->
You'll implement this in click event -
var page = new PageName();
Window.Current.Content = page;
Similar to Silverlight Navigation
If you are using Frame/Page Navigation then you can do it like this -
Create a shell page (master page) with the element declared. Then instead of creating new pages with create .
The easiest way to do this is to replace UserControl with Page
This is nicely explained in this tutorial -
http://www.markermetro.com/2011/11/technical/windows-8-metro-style-apps-implementing-navigation-with-xaml/
Hope it helps!
Regards,
Bhavik
Handle the Click event on the button and then call the Navigate method on your Frame
just type the following code in your click event
this->Frame->Navigate(TargetPageName::typeid,this);

Categories

Resources