Silverlight引用資源具體方法介紹
Silverlight開發(fā)工具的應用方法是比較簡單的。在實際的開發(fā)程序中,可以幫助開發(fā)人員輕松的實現(xiàn)各種視頻音頻WEB應用程序。在這里我們將會了解到有關Silverlight引用資源的一些相關介紹。#t#
下面討論三種在工程中Silverlight引用資源的方法:資源 Resource、內(nèi)容 content 和 none。
Silverlight引用資源1、默認情況下 mainPage.xaml 的 Build action 是 Page,而加入的資源文件則是 Resource。這樣,我們加入到 應用的根目錄下的圖片可以這樣引用。
- < UserControl x:Class="_009_uri.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"> - < Grid x:Name="LayoutRoot">
- < Image Source="./blend.jpg">< /Image>
- < /Grid>
- < /UserControl>
編譯后,可以看到圖片。
資源(Resource):這個build action選項會將文件嵌入項目的程序集中。這個選項意味著,如果你添加了一個視頻,那么你生成的xap會比你想象中的要大一些。
Silverlight引用資源2、 按照內(nèi)容的方式進行 build。我們先看一下代碼:
- < UserControl x:Class="_009_uri.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">- < Grid x:Name="LayoutRoot">
- < Image Source="./blend.jpg" Width="250"
Margin="0,0,300,0">< /Image>- < MediaElement Source="./old6.mp4"
Margin="250,50,0,0" Width="200">- < /MediaElement>
- < /Grid>
- < /UserControl>
雖然引用的方式?jīng)]有變化,但是此時我們必須將 jpg 和 mp4 文件放到網(wǎng)站的 ClientBin 或者其他和我們的應用同級的目錄中,才能夠正常的訪問,而此時,我們生成的 xap 又變成了一個小巧的文件包。
如果我們不適用相對的路徑,仍然可以用絕對的路徑來訪問我們的應用。
- < UserControl x:Class="_009_uri.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">- < Grid x:Name="LayoutRoot">
- < Image Source="./blend.jpg" Width="250"
Margin="0,0,300,0">< /Image>- < MediaElement Source="http://localhost
:7323/009_uri.Web/ClientBin/old6.mp4"
Margin="250,50,0,0" Width="200">- < /MediaElement>
- < /Grid>
- < /UserControl>
我認為,這種方法使我們?nèi)粘m椖恐薪?jīng)常用到的。
另外,如果我們使用前導斜杠(/)的相對URI,則表示我們要基于應用程序跟的位置來尋找Silverlight引用資源。
- < UserControl x:Class="_009_uri.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">- < Grid x:Name="LayoutRoot">
- < Image Source="./blend.jpg"
Width="250" Margin="0,0,300,0">< /Image>- < MediaElement Source="/../Assets/
old6.mp4" Margin="250,50,0,0"
Width="200">< /MediaElement>- < /Grid>
- < /UserControl>
Silverlight引用資源3、build action 為 none的時候,我們可以按照2的方式來進行引用。