WPF learning path (9) navigation link, wpf navigation link

Source: Internet
Author: User

WPF learning path (9) navigation link, wpf navigation link

Hyperlink

Hyperlink is a Hyperlink in WPF. In addition to navigation between pages, you can also navigate paragraphs under the same page.

 

Instance:

<Grid>    <FlowDocumentReader>        <FlowDocument>            <Section LineHeight="25" FontSize="15">                <List>                    <ListItem>                        <Paragraph>                            <Hyperlink NavigateUri="CustomPage.xaml#first">                                First Paragraph                            </Hyperlink>                        </Paragraph>                    </ListItem>                    <ListItem>                        <Paragraph>                            <Hyperlink NavigateUri="CustomPage.xaml#second">                                Second Paragraph                            </Hyperlink>                        </Paragraph>                    </ListItem>                </List>            </Section>            <Paragraph x:Name="first" FontSize="20" Background="AliceBlue">                1. First paragraph content            </Paragraph>            <Paragraph x:Name="second" FontSize="20" Background="AliceBlue">                2. Second paragraph content            </Paragraph>            <Paragraph>                <Hyperlink NavigateUri="SimplePage.xaml" >                    Hello WPF                </Hyperlink>            </Paragraph>        </FlowDocument>    </FlowDocumentReader></Grid>

 

 

If the page boarding window is not NavigationWindow, the hyperlink cannot be navigated.

 

 

By coding and navigation 

In some cases, Hyperlink cannot be implemented. It must be implemented through NavigationService.

1. values need to be passed in the navigation

2. Set properties before navigation to the page

3. You only need to know which page to navigate to when running

 

Instance:

DemoPage. xaml

 

<Page.Resources>    <Style TargetType="TextBlock">        <Setter Property="FontSize" Value="15" />        <Setter Property="Margin" Value="5" />    </Style></Page.Resources><StackPanel>    <TextBlock>        Navigate to         <Hyperlink x:Name="link1" Click="link_click">            SimplePage.xaml        </Hyperlink>    </TextBlock>    <TextBlock>        Navigate to         <Hyperlink x:Name="link2" Click="link_click">            SimplePage.xaml        </Hyperlink>        (Call a constructor with parameter)    </TextBlock>    <TextBlock>        Navigate to         <Hyperlink x:Name="link3" Click="link_click">            .Net Object        </Hyperlink>    </TextBlock>    <TextBlock>        Navigate to site        <Hyperlink x:Name="link4" Click="link_click">            http://www.bing.com        </Hyperlink>    </TextBlock></StackPanel>

 

class Person{    public string Name { get; set; }    public int Age { get; set; }    public override string ToString()    {        return "Name: " + Name + "\nAge: " + Age;    }}

Page. xaml. cs

private void link_click(object sender, RoutedEventArgs e){    Hyperlink link = sender as Hyperlink;    if (link == link1)    {        NavigationService.Navigate(new Uri("pack://application:,,,/SimplePage.xaml"));    }    else if (link == link2)    {        NavigationService.Navigate(new SimplePage("Hello Navigation"));    }else if (link == link3)    {        NavigationService.Navigate(new Person() { Name = "Alex", Age = 25 });    }    else if (link == link4)    {        NavigationService.Navigate(new Uri("http://www.bing.com"));    }}

 

 

Other navigation methods

Navigation Toolbar

 

Navigation command

Add a Button to control navigation, which is equivalent to a custom navigation toolbar.

<Button Height="50" Width="100" Content="Back" Command="NavigationCommands.BrowseBack" /><Button Height="50" Width="100" Content="Forward" Command="NavigationCommands.BrowseForward" />

 

 

 History

In WPF, Jaurnal records every navigation Operation to implement the navigation toolbar function.

Journal contains two data stacks to record the display status of the forward and backward pages. Each related Page corresponds to a JournalEntry. Automatic Log status recovery is only valid when you click the forward and backward buttons on the navigation bar.

 

 

 

 

 

 

 

 

 

 

To be continue...

 

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.