IT tutorials
 
Mobile
 

Windows Phone 8 : Page Navigation - Navigation Using Unmapped URIs

3/28/2014 3:56:31 AM
- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019

There are numerous ways of allowing the user to perform page navigation. This section looks at using Buttons with code-beside to open external URLs, and at HyperlinkButtons, which can rely solely on XAML.

Internal URIs

When navigating to PhoneApplicationPages within an application, URIs either must be relative to the root directory of the project and use the relative path syntax, as shown in the following excerpt:

Uri uri = new Uri("/DirectoryName/PageName.xaml", UriKind.Relative);

or they must use the relative component URI format, such as that used in the following example:

Uri uri = new Uri("/AssemblyName;component/PageName.xaml", UriKind.Relative);

The assembly name segment must be the name of an assembly that is locatable at runtime. The name of a project’s output assembly can be found in the project properties editor by right-clicking the project node in the Solution Explorer and selecting Properties, or by pressing Alt+Enter.

The HyperlinkButton control can be used to allow the user to navigate directly to a page within your application, as shown:

<HyperlinkButton NavigateUri="/Directory/PageName.xaml" Content="Internal Page" />

External Navigation Using the Button Control

The Button control is a flexible way for determining user intent. A Button can be used for navigation by subscribing to its Click event, as shown in the following excerpt from the ProductDetailsView.xaml in the downloadable sample code:

<Button Click="Button_ExternalLink_Click"
        Tag="{Binding Product.ExternalUrl}"
        Content="External Page" />

The WebBrowserTask allows you to navigate to external URIs using the phone’s built-in web browser Internet Explorer. This causes your app to be deactivated while the user views the page.

To provide the WebBrowserTask with the location of the web page, use the button’s Tag property. The Click event handler, which initiates the WebBrowserTask, is shown in the following excerpt:

void Button_ExternalLink_Click(object sender, RoutedEventArgs e)
{
    FrameworkElement button = sender as FrameworkElement;
    if (button == null || button.Tag == null)
    {
        return;
    }
    WebBrowserTask task = new WebBrowserTask
    {
        Uri = new Uri(button.Tag.ToString(), UriKind.Absolute)
    };
    task.Show();
}

External Navigation Using the HyperlinkButton Control

The disadvantage of using a Button control for links to external content is that it does not provide the familiar look and feel of a hyperlink. The HyperlinkButton control provides an easier way for navigating to pages within an application. There is a trick to using the HyperlinkButton with external URIs. Set its TargetName property to _blank, as shown in the following example:

<HyperlinkButton TargetName="_blank" NavigateUri="http://create.msdn.com"
                 Content="http://create.msdn.com" />


Note

Failing to set the HyperlinkButton.TargetName to _blank, when using an external URI, raises the Frame.NavigationFailed event when the button is tapped.


Hosting Web Content Within an App

An alternative to using the phone’s built-in Internet Explorer app is to host the content in a Microsoft.Phone.Controls.WebBrowser control.

The following excerpt from the WebBrowserView.xaml page, in the downloadable sample code, shows a WebBrowser placed within the main content grid of a page:

<Grid x:Name="ContentGrid" Grid.Row="1">
    <phone:WebBrowser Source="{Binding Url}"/>
</Grid>

Here the Source property of the WebBrowser is bound to the Url property of the viewmodel.

A dedicated web browser page can be used in your app to host all external content. To launch the dedicated web browser page, a relative URI can be constructed using the Binding.StringFormat property, as shown in the following excerpt:

<HyperlinkButton
    NavigateUri="{Binding ExternalUrl, StringFormat=/WebBrowser/\{0\}}"
    Content="External Page" />

Backslashes are used to escape the curly brackets in the StringFormat value.

The StringFormat property transforms the HyperlinkButton’s binding expression into the following:

string.Format("/WebBrowser/{0}", ExternalUrl);

URI mapping is used to pass the external URL as a query string parameter. This is explored further in a later section.

 
Others
 
- Windows Phone 8 : Understanding the Application Execution Model - Running Under the Lock Screen - Lock Screen Management
- Windows Phone 8 : Understanding the Application Execution Model - Implementing Fast App Resume - Optimizing the Resume Experience
- Windows Phone 8 : Exploring the Execution Model (part 4) - Restoring Transient State, Saving Persistent State
- Windows Phone 8 : Exploring the Execution Model (part 3) - Programmatically Exiting an App , Saving Transient State
- Windows Phone 8 : Exploring the Execution Model (part 2) - Life Cycle Events
- Windows Phone 8 : Exploring the Execution Model (part 1) - Application State
- Windows Phone 7 to Windows Phone 8 : App publication (part 7) - Selective targeting - Device memory
- Windows Phone 7 to Windows Phone 8 : App publication (part 6) - Selective targeting - Device capabilities
- Windows Phone 7 to Windows Phone 8 : App publication (part 5) - Beta testing, Versions
- Windows Phone 7 to Windows Phone 8 : App publication (part 4) - Updates
 
 
Top 10
 
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
Technology FAQ
- Is possible to just to use a wireless router to extend wireless access to wireless access points?
- Ruby - Insert Struct to MySql
- how to find my Symantec pcAnywhere serial number
- About direct X / Open GL issue
- How to determine eclipse version?
- What SAN cert Exchange 2010 for UM, OA?
- How do I populate a SQL Express table from Excel file?
- code for express check out with Paypal.
- Problem with Templated User Control
- ShellExecute SW_HIDE
programming4us programming4us