SIGN UP MEMBER LOGIN:    
ARTICLE

Hyperlink in C#

Posted by Gomathi Palaniswamy Articles | C# Language June 16, 2011
The hyperlink is the control to link another page. The hyperlink can navigate to “URL” as well as xaml page.
Reader Level:


The HyperLink Control is the control to link to another page. The HyperLink can navigate to an "URL" as well as an XAML page.

HyperLink properties:

  1. Background: The background property used to change the background color of the HyperLink control.
  2. ClickMode: The click mode says when to fire a click event.
  3. Foreground: It's the property to change color of the font of content.
  4. Content: Is the content of the control.
  5. Name: Name of the control.
  6. Fontfamily: Font type of the HyperLink content.
  7. Horizontal alignment and vertical alignment: These align the HyperLink control.
  8. Horizontalcontentalignment and  verticalcontentalignment: Aligns the content of the control.
  9. Click: The click event that is fired when the control is clicked

XAML page :

<UserControl xmlns:input="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Input"  x:Class="ControlSamples.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480">
    <ScrollViewer>
        <StackPanel Orientation="Vertical">
            <StackPanel>
                <Grid x:Name="LayoutRoot" Width="1000" Height="100" VerticalAlignment="Top">

                    <Grid.Background>
                        <LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
                            <GradientStop Color="SkyBlue"  Offset="0"/>
                            <GradientStop Color="White"  Offset="0.75"/>
                            <GradientStop Color="SkyBlue"  Offset="1"/>
                        </LinearGradientBrush>
                    </Grid.Background>
                </Grid>
            </StackPanel>
            <StackPanel Height="500" Width="200" HorizontalAlignment="Left" Margin="0,10,0,0" >
                <StackPanel.Background>
                    <LinearGradientBrush StartPoint="0,0" EndPoint="0.5,1">
                        <GradientStop Color="SkyBlue"  Offset="0"/>
                        <GradientStop Color="White"  Offset="1"/>
                    </LinearGradientBrush>
                </StackPanel.Background>
                <HyperlinkButton Background="Yellow" Name="MyHyperlink" ClickMode="Press" Content="AutoCompleteBox"   Foreground="Blue" FontFamily="Arial" FontSize="15" Click="HyperlinkButton_Click" ></HyperlinkButton>
            </StackPanel>

        </StackPanel>

    </ScrollViewer>

</UserControl>

The XAML page has the design of the page with the HyperLink Control.

Navigation:

<HyperlinkButton Background="Yellow" Name="MyHyperlink" ClickMode="Press" Content="AutoCompleteBox"   Foreground="Blue" FontFamily="Arial" FontSize="15" NavigateUri="http:\\www.google.com">
</HyperlinkButton>

This navigates to the Google page.

Navigation from XAML to another XAML:

<HyperlinkButton Background="Yellow" Name="MyHyperlink" ClickMode="Press" Content="AutoCompleteBox"   Foreground="Blue" FontFamily="Arial" FontSize="15" Click="HyperlinkButton_Click" ></HyperlinkButton>

C#

        private void HyperlinkButton_Click(object sender, RoutedEventArgs e)
        {
            this.Content=new Page1();
         
        }

Thank you!!!
 

Login to add your contents and source code to this article
share this article :
post comment
 
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
Team Foundation Server Hosting
Become a Sponsor