Silverlight引用资源具体方法介绍
创始人
2024-06-19 00:41:53
0

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的方式来进行引用。

相关内容

热门资讯

如何允许远程连接到MySQL数... [[277004]]【51CTO.com快译】默认情况下,MySQL服务器仅侦听来自localhos...
如何利用交换机和端口设置来管理... 在网络管理中,总是有些人让管理员头疼。下面我们就将介绍一下一个网管员利用交换机以及端口设置等来进行D...
施耐德电气数据中心整体解决方案... 近日,全球能效管理专家施耐德电气正式启动大型体验活动“能效中国行——2012卡车巡展”,作为该活动的...
Windows恶意软件20年“... 在Windows的早期年代,病毒游走于系统之间,偶尔删除文件(但被删除的文件几乎都是可恢复的),并弹...
20个非常棒的扁平设计免费资源 Apple设备的平面图标PSD免费平板UI 平板UI套件24平图标Freen平板UI套件PSD径向平...
德国电信门户网站可实时显示全球... 德国电信周三推出一个门户网站,直观地实时提供其安装在全球各地的传感器网络检测到的网络攻击状况。该网站...
着眼MAC地址,解救无法享受D... 在安装了DHCP服务器的局域网环境中,每一台工作站在上网之前,都要先从DHCP服务器那里享受到地址动...
为啥国人偏爱 Mybatis,... 关于 SQL 和 ORM 的争论,永远都不会终止,我也一直在思考这个问题。昨天又跟群里的小伙伴进行...