Silverlight引用资源具体方法介绍

开发 开发工具
Silverlight引用资源的方法总共可以分为三种,分别为:资源 Resource、内容 content 和 none。本文将会为大家详细介绍其中概念。

Silverlight开发工具的应用方法是比较简单的。在实际的开发程序中,可以帮助开发人员轻松的实现各种视频音频WEB应用程序。在这里我们将会了解到有关Silverlight引用资源的一些相关介绍。#t#

下面讨论三种在工程中Silverlight引用资源的方法:资源 Resource、内容 content 和 none。

Silverlight引用资源1、默认情况下 mainPage.xaml 的 Build action 是 Page,而加入的资源文件则是 Resource。这样,我们加入到 应用的根目录下的图片可以这样引用。

  1. < UserControl x:Class="_009_uri.MainPage" 
  2. xmlns="http://schemas.microsoft.
    com/winfx/2006/xaml/presentation"
       
  3. xmlns:x="http://schemas.microsoft.
    com/winfx/2006/xaml"
     
  4. xmlns:d="http://schemas.microsoft.
    com/expression/blend/2008"
     xmlns:mc=
    "http://schemas.openxmlformats.org
    /markup-compatibility/2006"
       
  5. mc:Ignorable="d" d:DesignWidth="640" 
    d:DesignHeight="480"> 
  6. < Grid x:Name="LayoutRoot"> 
  7. < Image Source="./blend.jpg">< /Image> 
  8. < /Grid> 
  9. < /UserControl> 

 

编译后,可以看到图片。

资源(Resource):这个build action选项会将文件嵌入项目的程序集中。这个选项意味着,如果你添加了一个视频,那么你生成的xap会比你想象中的要大一些。

Silverlight引用资源2、 按照内容的方式进行 build。我们先看一下代码:

  1.  
  2. < UserControl x:Class="_009_uri.MainPage" 
  3. xmlns="http://schemas.microsoft.com
    /winfx/2006/xaml/presentation"
       
  4. xmlns:x="http://schemas.microsoft.
    com/winfx/2006/xaml"
     
  5. xmlns:d="http://schemas.microsoft.com
    /expression/blend/2008"
     xmlns:mc=
    "http://schemas.openxmlformats.org
    /markup-compatibility/2006"
       
  6. mc:Ignorable="d" d:DesignWidth="640"
     d:DesignHeight="480"> 
  7. < Grid x:Name="LayoutRoot"> 
  8. < Image Source="./blend.jpg" Width="250"
     Margin="0,0,300,0">< /Image> 
  9. < MediaElement Source="./old6.mp4"
     Margin="250,50,0,0" Width="200">
  10. < /MediaElement> 
  11. < /Grid> 
  12. < /UserControl> 

 

虽然引用的方式没有变化,但是此时我们必须将 jpg 和 mp4 文件放到网站的 ClientBin 或者其他和我们的应用同级的目录中,才能够正常的访问,而此时,我们生成的 xap 又变成了一个小巧的文件包。

如果我们不适用相对的路径,仍然可以用绝对的路径来访问我们的应用。

 

  1. < UserControl x:Class="_009_uri.MainPage" 
  2. xmlns="http://schemas.microsoft.com/
    winfx/2006/xaml/presentation"
       
  3. xmlns:x="http://schemas.microsoft.com
    /winfx/2006/xaml"
     
  4. xmlns:d="http://schemas.microsoft.com
    /expression/blend/2008"
     xmlns:mc="http
    ://schemas.openxmlformats.org/markup-
    compatibility/2006"
       
  5. mc:Ignorable="d" d:DesignWidth="640" 
    d:DesignHeight="480"> 
  6. < Grid x:Name="LayoutRoot"> 
  7. < Image Source="./blend.jpg" Width="250"
     Margin="0,0,300,0">< /Image> 
  8. < MediaElement Source="http://localhost
    :7323/009_uri.Web/ClientBin/old6.mp4"
     
    Margin="250,50,0,0" Width="200">
  9. < /MediaElement> 
  10. < /Grid> 
  11. < /UserControl> 

 

我认为,这种方法使我们日常项目中经常用到的。

 

另外,如果我们使用前导斜杠(/)的相对URI,则表示我们要基于应用程序跟的位置来寻找Silverlight引用资源。

 

  1. < UserControl x:Class="_009_uri.MainPage" 
  2. xmlns="http://schemas.microsoft.com
    /winfx/2006/xaml/presentation"
       
  3. xmlns:x="http://schemas.microsoft
    .com/winfx/2006/xaml"
     
  4. xmlns:d="http://schemas.microsoft.
    com/expression/blend/2008"
     xmlns:mc=
    "http://schemas.openxmlformats.org
    /markup-compatibility/2006"
       
  5. mc:Ignorable="d" d:DesignWidth="640" 
    d:DesignHeight="480"> 
  6. < Grid x:Name="LayoutRoot"> 
  7. < Image Source="./blend.jpg" 
    Width="250" Margin="0,0,300,0">< /Image> 
  8. < MediaElement Source="/../Assets/
    old6.mp4"
     Margin="250,50,0,0" 
    Width="200">< /MediaElement> 
  9. < /Grid> 
  10. < /UserControl> 

Silverlight引用资源3、build action 为 none的时候,我们可以按照2的方式来进行引用。

责任编辑:曹凯 来源: 博客园
相关推荐

2009-12-31 15:05:00

Silverlight

2009-12-16 15:04:26

Ruby实现strea

2010-03-19 15:47:49

Python语法检查

2009-12-01 13:41:49

静态路由设置

2009-11-23 15:10:28

PHP获取当前url

2009-11-30 11:24:49

PHP将EXCEL导入

2009-12-01 09:52:40

PHP过滤字符串

2009-11-24 17:25:00

PHP二维数组排序

2010-07-21 14:33:01

删除telnet

2011-04-01 13:34:12

zabbix

2009-12-29 18:02:26

SilverLight

2009-12-03 14:43:46

phpMyAdmin配

2010-01-04 15:21:37

Silverlight

2010-04-23 13:53:29

Oracle密码

2009-12-29 18:34:21

Silverlight

2009-12-15 13:47:33

Silverlight

2009-12-25 16:52:57

网络接入控制

2010-02-06 11:19:33

C++获取文件

2009-11-23 19:16:32

路由器测试

2009-12-31 17:21:41

Silverlight
点赞
收藏

51CTO技术栈公众号