WPF Learning Path (ix) navigation links

Source: Internet
Author: User

Hyperlink

The type of hyperlink in WPF is hyperlink, in addition to being able to navigate between pages, and to navigate the same page under a paragraph

Instance:

<Grid> <FlowDocumentReader> <FlowDocument> <section lineheight=" -"Fontsize=" the"> <List> <ListItem> <Paragraph> "Custompage.xaml#first">First Paragraph</Hyperlink> </Paragraph> </ListItem> <l istitem> <Paragraph> "Custompage.xaml#second">Second Paragraph</Hyperlink> </Paragraph> </ListItem> </list > </Section> <paragraph x:name=" First"Fontsize=" -"Background="AliceBlue">1. First paragraph content</Paragraph> <paragraph x:name="Second"Fontsize=" -"Background="AliceBlue">2. Second paragraph content</Paragraph> <Paragraph> "Simplepage.xaml">Hello WPF</Hyperlink> </Paragraph> </FlowDocument> </FlowDocumentReader></Grid>

If the page host window is not NavigationWindow, the hyperlink is not navigable

Navigating by writing code

In some cases, hyperlink cannot be implemented and needs to be implemented by NavigationService

1. Navigation needs to pass value

2. To set properties before navigating to the page

3. The runtime only knows which page to navigate to

Instance:

Demopage.xaml

<Page.Resources> <style targettype="TextBlock"> <setter property="FontSize"Value=" the"/> <setter property="Margin"Value="5"/> </Style></Page.Resources><StackPanel> <TextBlock>Navigate to"Link1"click="Link_click">Simplepage.xaml</Hyperlink> </TextBlock> <TextBlock>Navigate to"Link2"click="Link_click">Simplepage.xaml</Hyperlink>(call a constructor with parameter)</TextBlock> <TextBlock>Navigate to"Link3"click="Link_click">. Net Object</Hyperlink> </TextBlock> <TextBlock>Navigate to Site"Link4"click="Link_click">http://www.bing.com</Hyperlink> </TextBlock></StackPanel>

classperson{ Public stringName {Get;Set; }  Public intAge {Get;Set; }  Public Override stringToString () {return "Name:"+ Name +"\nage:"+Age ; }}

Page.xaml.cs

Private voidLink_click (Objectsender, RoutedEventArgs e) {Hyperlink link= Sender asHyperlink; if(link = =Link1) {Navigationservice.navigate (NewUri ("pack://application:,,,/simplepage.xaml")); }    Else if(link = =link2) {Navigationservice.navigate (NewSimplePage ("Hello Navigation")); }Else if(link = =Link3) {Navigationservice.navigate (NewPerson () {Name ="Alex", age = - }); }    Else if(link = =Link4) {Navigationservice.navigate (NewUri ("http://www.bing.com")); }}

Other ways to navigate

Navigation toolbar

Navigation commands

Add button control navigation, equivalent to custom navigation toolbar

<button height=" -"Width=" -"Content=" Back"Command="Navigationcommands.browseback"/><button height=" -"Width=" -"Content="Forward"Command="Navigationcommands.browseforward"/>

Historical Records

In WPF, Jaurnal records each navigation operation, enabling the navigation toolbar to function

The Journal contains two data stacks to record the display status of the forward and backward pages, and each related page corresponds to a journalentry. Log state AutoRecover is only valid for clicking the Forward Back button on the navigation bar.

To be continue ...

WPF Learning Path (ix) navigation links

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.