数据绑定:从DHTML迁移到Xmal(1)
从最简单的开始:
在DHTML中,我们可以使用数据岛进行数据绑定,参考
http://msdn.microsoft.com/library/default.asp?url=/workshop/author/databind/dataconsumer.asp
http://msdn.microsoft.com/library/default.asp?url=/workshop/author/databind/architecture.asp
例子:
--------------------test.htm-------------------------
<xml id='DataSource'>
<Books>
<Book ISBN="0-7356-0562-9" Stock="in">
<Title>XML in Action</Title>
<Summary>XML Web Technology</Summary>
</Book>
<Book ISBN="0-7356-1370-2" Stock="in">
<Title>Programming Microsoft Windows With C#</Title>
<Summary>C# Programming using the .NET Framework</Summary>
</Book>
<Book ISBN="0-7356-1288-9" Stock="out">
<Title>Inside C#</Title>
<Summary>C# Language Programming</Summary>
</Book>
<Book ISBN="0-7356-1377-X" Stock="in">
<Title>Introducing Microsoft .NET</Title>
<Summary>Overview of .NET Technology</Summary>
</Book>
<Book ISBN="0-7356-1448-2" Stock="out">
<Title>Microsoft C# Language Specifications</Title>
<Summary>The C# language definition</Summary>
</Book>
</Books>
</xml>
<H3>XML Data Source Sample</H3>
<table datasrc="#DataSource">
<tr>
<td>
<span datafld="Title"></span>
</td>
</tr>
</table>
--------------------------------------------------------------<Books>
<Book ISBN="0-7356-0562-9" Stock="in">
<Title>XML in Action</Title>
<Summary>XML Web Technology</Summary>
</Book>
<Book ISBN="0-7356-1370-2" Stock="in">
<Title>Programming Microsoft Windows With C#</Title>
<Summary>C# Programming using the .NET Framework</Summary>
</Book>
<Book ISBN="0-7356-1288-9" Stock="out">
<Title>Inside C#</Title>
<Summary>C# Language Programming</Summary>
</Book>
<Book ISBN="0-7356-1377-X" Stock="in">
<Title>Introducing Microsoft .NET</Title>
<Summary>Overview of .NET Technology</Summary>
</Book>
<Book ISBN="0-7356-1448-2" Stock="out">
<Title>Microsoft C# Language Specifications</Title>
<Summary>The C# language definition</Summary>
</Book>
</Books>
</xml>
<H3>XML Data Source Sample</H3>
<table datasrc="#DataSource">
<tr>
<td>
<span datafld="Title"></span>
</td>
</tr>
</table>
迁移到XMAL中,参考
ms-help://MS.MSDNQTR.v80.en/MS.MSDN.v80/MS.WinFX4VS.1033/Wcp_samples/local/samplehtmlsources/ConnectedData/XmlDataSource/XAML/Window1.xaml.htm
有一点Xslt的意思,比如使用了模版以及标准的XPath
-----------------------Window1.xaml--------------------------
<StackPanel
xmlns="http://schemas.microsoft.com/winfx/avalon/2005"
xmlns:x="http://schemas.microsoft.com/winfx/xaml/2005"
Background="Cornsilk"
>
<StackPanel.Resources>
<XmlDataProvider x:Key="BookData" XPath="/Books">
<Books xmlns="">
<Book ISBN="0-7356-0562-9" Stock="in">
<Title>XML in Action</Title>
<Summary>XML Web Technology</Summary>
</Book>
<Book ISBN="0-7356-1370-2" Stock="in">
<Title>Programming Microsoft Windows With C#</Title>
<Summary>C# Programming using the .NET Framework</Summary>
</Book>
<Book ISBN="0-7356-1288-9" Stock="out">
<Title>Inside C#</Title>
<Summary>C# Language Programming</Summary>
</Book>
<Book ISBN="0-7356-1377-X" Stock="in">
<Title>Introducing Microsoft .NET</Title>
<Summary>Overview of .NET Technology</Summary>
</Book>
<Book ISBN="0-7356-1448-2" Stock="out">
<Title>Microsoft C# Language Specifications</Title>
<Summary>The C# language definition</Summary>
</Book>
</Books>
</XmlDataProvider>
<DataTemplate x:Key="BookDataTemplate">
<TextBlock FontSize="12" Foreground="Red">
<TextBlock.Text>
<Binding XPath="Title"/>
</TextBlock.Text>
</TextBlock>
</DataTemplate>
</StackPanel.Resources>
<TextBlock FontSize="18" FontWeight="Bold" Margin="10"
HorizontalAlignment="Center">XML Data Source Sample</TextBlock>
<ListBox
Width="400" Height="300" Background="Honeydew"
ItemsSource="{Binding Source={StaticResource BookData}, XPath=Book}"
ItemTemplate="{StaticResource BookDataTemplate}"/>
</StackPanel>
posted on 2006-02-06 11:11 civ3's .NET studying 阅读(472) 评论(0) 编辑 收藏 举报