Silverlight數(shù)據(jù)異步通信實際操作方法介紹
Silverlight開發(fā)工具是由微軟推出的一款跨平臺的音頻視頻處理工具??梢詭椭绦騿T輕松的實現(xiàn)各種圖形,多媒體方面的功能需求。在這里我們就先來了解一下有關(guān)Silverlight數(shù)據(jù)異步通信的相關(guān)操作方法。#t#
開始本來是用silverlight Beta1完成的,后來越做越發(fā)現(xiàn)很多功能和屬性用著麻煩也不太好用了,最后干脆就改成了Beta2了,畢竟是最新版,果然用著舒服些啊。 整個功能完成的比較順利,當(dāng)中也遇到了幾個稍微麻煩點的問題。比如在Silverlight項目中圖片路徑賦值的問題。設(shè)置圖片Source路徑必須是ImageSource,我的是"jay.jpg"路徑怎么轉(zhuǎn)?在Api里翻了半天,也沒發(fā)現(xiàn)。最后到網(wǎng)上查了下, 網(wǎng)上搜了半天沒個結(jié)果,最后瞎折騰了半天用獲取網(wǎng)絡(luò)資源的方式,竟然成功了。方式:
- new BitmapImage(new Uri(System.
Windows.B
rowser.HtmlPage.Document.
DocumentUri, "Images/a.jpg");
不過,這個Silverlight數(shù)據(jù)異步通信的方式不好的地方就是不能把圖片放入Silverlight項目中打包,只能把圖片轉(zhuǎn)移到Web Application里去了。
下面是Silverlight項目xaml部分源碼了。
- < UserControl x:Class="SilverlightTravel.
NetWebClient"- xmlns="http://schemas.microsoft.com/
winfx/2006/xaml/presentation"- xmlns:x="http://schemas.microsoft.
com/winfx/2006/xaml"- Width="600" Height="300" Loaded=
"UserControl_Loaded">- < Grid x:Name="LayoutRoot" Background=
"WhiteSmoke" ShowGridLines="True">- < Grid.RowDefinitions>
- < RowDefinition Height="30">
- < /RowDefinition>
- < RowDefinition Height="150">
- < /RowDefinition>
- < RowDefinition Height="200">
- < /RowDefinition>
- < /Grid.RowDefinitions>
- < Grid.ColumnDefinitions>
- < ColumnDefinition Width="200">
- < /ColumnDefinition>
- < ColumnDefinition Width="*">
- < /ColumnDefinition>
- < /Grid.ColumnDefinitions>
- < TextBlock Text="請選擇人物查看介紹"
Grid.Column="0" Grid.Row="0">< /TextBlock>- < ListBox Grid.Column="0" x:Name=
"lstMusicer" Grid.Row="1" Width="200"
HorizontalAlignment="Left" SelectionChanged=
"lstMusicer_SelectionChanged">- < ListBox.ItemTemplate>
- < DataTemplate>
- < StackPanel>
- < TextBlock Text="{Binding UserName}"
Height="35">< /TextBlock>- < /StackPanel>
- < /DataTemplate>
- < /ListBox.ItemTemplate>
- < /ListBox>
- < Image x:Name="imgPerson" HorizontalAlignment=
"Left" Grid.Row="1" Grid.Column="1">< /Image>- < MediaElement x:Name="mePlayer"
HorizontalAlignment="Left" Source="video/"
Grid.Row="2" Grid.Column="2" Height="50"
Width="50">< /MediaElement>- < TextBlock x:Name="txtIntroduce" Grid.Row="2"
Grid.Column="1" Margin="30 50 " Grid.ColumnSpan="2">- < /TextBlock>
- < Button Height="50" VerticalAlignment="Top"
Margin="10 " Width="120" Grid.Row="2"
Grid.Column="0" Background="Red"
Content="數(shù)據(jù)異步通信">< /Button>- < /Grid>
- < /UserControl>
Silverlight數(shù)據(jù)異步通信的具體操作方法就為大家介紹到這里,希望能對大家有所幫助。