Silverlight基本控件学习笔记(十)[HyperlinkButton]

主要问题是路径的设置,相对路径及绝对路径。

示例代码:

<UserControl x:Class="HyperlineButtonDemo.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:DesignHeight="300" d:DesignWidth="400" Loaded="UserControl_Loaded">

    <Grid x:Name="LayoutRoot" Background="White">
        <Grid.RowDefinitions>
            <RowDefinition>
               
            </RowDefinition>
            <RowDefinition></RowDefinition>
            <RowDefinition></RowDefinition>
        </Grid.RowDefinitions>
        <HyperlinkButton NavigateUri="http://www.baidu.com" Grid.Row="1" Width="80" Height="30" Content="绝对地址" TargetName="_blank"/>
        <HyperlinkButton  Grid.Row="2" Width="80" Height="30" Content="新窗口打开我的博客" TargetName="_blank" Click="HyperlinkButton_Click"/>

    </Grid>
</UserControl>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace HyperlineButtonDemo
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
        }

        private void HyperlinkButton_Click(object sender, RoutedEventArgs e)
        {
            System.Windows.Browser.HtmlPage.Window.Eval("window.open(\'http://www.cnblogs.com/steven_gsj/\')");
        }

        private void hyperlinkBtn_Click(object sender, RoutedEventArgs e)
        {
           // (sender as HyperlinkButton).NavigateUri = new Uri("ImageDemoTestPage.aspx", UriKind.Relative);
        }

        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            HyperlinkButton hyperlinkBtn = new HyperlinkButton();
            hyperlinkBtn.Width = 80;
            hyperlinkBtn.Height = 30;
            hyperlinkBtn.Content = "相对地址";
            hyperlinkBtn.TargetName = "_blank";
            hyperlinkBtn.NavigateUri = new Uri(Application.Current.Host.Source,"../ImageDemoTestPage.aspx");
            LayoutRoot.Children.Add(hyperlinkBtn);
          
        }
    }
}

 

关于相对路径及绝对路径的解释请参看:

http://www.cnblogs.com/sutengcn/archive/2008/08/17/201993.html

Silverlight中的相对路径和绝对路径

http://hi.baidu.com/liongg/blog/item/b91a495494e34152564e00b4.html

我个人认为要把以前用的路径设置和silverlight中的路径设置分开思考,

通常情况下“/”表示网站的根,而在Silvelight中"/"却可能表示ClientBin目录。。。

同时如果考虑到资源访问的问题请参考:

http://hi.baidu.com/liongg/blog/item/c258f8194c02ec7cdab4bd4f.html

你可能感兴趣的:(silverlight)