--------------------------------------------------------------------------------
引用或轉(zhuǎn)載時(shí)請(qǐng)保留以下信息:
大可山 [MSN:a3news(AT)hotmail.com]
http://www.zpxp.com http://www.brawdraw.com
蘿卜鼠在線圖形圖像處理
--------------------------------------------------------------------------------
3、使用外部URL鏈接的XML文件作為數(shù)據(jù)源
事實(shí)上,在上文Windows Presentation Foundation(WPF)中的數(shù)據(jù)綁定(使用XmlDataProvider作控件綁定) 中,XmlDataProvider的Source屬性還可以直接指向你本機(jī)的某個(gè)XML文件:
<XmlDataProvider x:Key="FavoriteColors" Source="E:\Books\xaml\FavoriteColors.xml" />
我們還可以指向任何標(biāo)準(zhǔn) URL,這樣,我們就可以創(chuàng)建對(duì)XML API(如 RSS)的快速訪問。
比如,我的BLOG中關(guān)于WPF的RSS地址是: >
<Canvas x:Name="LayoutRoot">
<StackPanel Height="243.687">
<StackPanel.Resources>
<XmlDataProvider x:Key="MyRSS"
Source="http://blog.csdn.net/johnsuna/category/325343.aspx/rss" />
</StackPanel.Resources>
<TextBlock x:Name="txtBlockTitle" Text="{Binding Source={StaticResource MyRSS}, XPath=//channel/title}" HorizontalAlignment="Center"
FontWeight="Bold"/>
<ListBox Width="500" Height="300"
ItemsSource="{Binding Source={StaticResource MyRSS}, XPath=//item/title}">
</ListBox>
</StackPanel>
</Canvas>
</Window>
上面 XPath=//channel/title , XPath=//item/title分別對(duì)應(yīng)下面的具體內(nèi)容,你可以結(jié)合起來仔細(xì)分析一下。(如果你對(duì)XPath的相關(guān)細(xì)節(jié)不夠了解,建議你看一下XSLT相關(guān)的書或者到以下鏈接:http://www.w3.org/TR/xpath,http://www.w3schools.com/xpath/default.asp)
這是http://blog.csdn.net/johnsuna/category/325343.aspx/rss的部分內(nèi)容:(注意我特別加粗的部分)
<rss version="2.0" xmlns:dc=" </item>
<item>
<dc:creator>大可山</dc:creator>
<title>Windows Presentation Foundation(WPF)中的數(shù)據(jù)綁定(控件與控件值的綁定)</title>
<link>http://blog.csdn.net/johnsuna/archive/2007/08/21/1752865.aspx</link>
<pubDate>Tue, 21 Aug 2007 14:51:00 GMT</pubDate>
<guid>http://blog.csdn.net/johnsuna/archive/2007/08/21/1752865.aspx</guid>
<wfw:comment>http://blog.csdn.net/johnsuna/comments/1752865.aspx</wfw:comment>
<comments>http://blog.csdn.net/johnsuna/archive/2007/08/21/1752865.aspx#Feedback</comments>
<slash:comments>0</slash:comments>
<wfw:commentRss>http://blog.csdn.net/johnsuna/comments/commentRss/1752865.aspx</wfw:commentRss>
<trackback:ping>http://tb.blog.csdn.net/TrackBack.aspx?PostId=1752865</trackback:ping>
<description>使用類似{Binding ElementName=txtBoxInput,Path=Text}的方式進(jìn)行控件與控件的綁定<img src =" </item>
<!-- 還有更多 -->
</channel>
</rss>
下圖是顯示效果:
聯(lián)系客服