WPF绑定XML ListBox显示
来源:互联网 发布:网络社会中的政治表达 编辑:程序博客网 时间:2024/05/23 00:01
Window1.xaml 前台代码
<Window x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="WPFDataBindingXML" Height="372" Width="462">
<Window.Resources>
<XmlDataProvider x:Key="guestSource" Source="guest.xml" XPath="/Guests/*"/>
<DataTemplate x:Key="showTitle">
<TextBlock Text="{Binding XPath=Title}"/>
</DataTemplate>
<Style TargetType="{x:Type TextBlock}">
<Setter Property="FontStyle" Value="Italic"/>
<Setter Property="FontFamily" Value="Trebuchet MS"/>
<Setter Property="FontSize" Value="12"/>
</Style>
</Window.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<ListBox Grid.Row="0" Grid.Column="0" Margin="5,5,5,5" ItemsSource="{Binding Source={StaticResource guestSource}}"
ItemTemplate="{StaticResource showTitle}" IsSynchronizedWithCurrentItem="True">
</ListBox>
<StackPanel Grid.Row="0" Grid.Column="1" Margin="5,5,5,5">
<TextBlock>
Title:
<TextBlock Margin="10,0,0,0" DataContext="{Binding Source={StaticResource guestSource}}" Text="{Binding XPath=Title}"/>
</TextBlock>
<TextBlock>
Coment:
<TextBlock Margin="10,0,0,0" DataContext="{Binding Source={StaticResource guestSource}}" Text="{Binding XPath=Coment}"/>
</TextBlock>
<TextBlock>
Reply:
<TextBlock Margin="10,0,0,0" DataContext="{Binding Source={StaticResource guestSource}}" Text="{Binding XPath=Reply}"/>
</TextBlock>
</StackPanel>
</Grid>
</Window>
******************************************************
guest.xml 数据结构
<?xml version="1.0" encoding="utf-8" ?>
<Guests>
<xs:schema id="Guests" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="Guests" msdata:IsDataSet="true">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element name="Guest">
<xs:complexType>
<xs:sequence>
<xs:element name="Title" type="xs:string" minOccurs="0" />
<xs:element name="Coment" type="xs:string" minOccurs="0" />
<xs:element name="Reply" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
<Guest>
<Title>sohu</Title>
<Coment>job plan</Coment>
<Reply>嘿嘿呵呵</Reply>
</Guest>
<Guest>
<Title>why?</Title>
<Coment>because ?</Coment>
<Reply>嘿嘿?</Reply>
</Guest>
<Guest>
<Title>fet</Title>
<Coment>job plan</Coment>
<Reply>嘿嘿呵呵</Reply>
</Guest>
<Guest>
<Title>goog</Title>
<Coment>job plan</Coment>
<Reply>嘿嘿呵呵</Reply>
</Guest>
<Guest>
<Title>heal</Title>
<Coment>job plan</Coment>
<Reply>嘿嘿呵呵</Reply>
</Guest>
</Guests>
- WPF绑定XML ListBox显示
- WPF: ListBox绑定xml数据
- WPF绑定ListBox
- WPF ListBox数据绑定
- WPF 绑定实例之 LISTBOX显示 图片列表
- WPF 绑定实例之 LISTBOX显示 图片列表
- WPF listbox combobox简单绑定
- WPF - ListBox显示任意内容
- WPF ListBox等控件绑定集合
- WPF绑定XML数据源
- WPF XAML绑定xml
- WPF中的ListBox按块显示元素
- WPF中,ListBox与数据间的绑定
- WPF中ListBox的创建和多种绑定用法
- WPF中ListBox的创建和多种绑定用法
- WPF中ListBox的创建和多种绑定用法
- WPF listbox异步绑定数据IsAsync=True
- WPF学习笔记——ListBox用ItemsSource绑定数据源
- extern "C" 3条提示
- fpga 二进制转bcd码 模块(经典)
- TC35调试笔记
- 好搞笑的笑话
- 各省大学生兼职qq群
- WPF绑定XML ListBox显示
- 关于二进制
- 哈佛图书馆自习室墙上的训言
- fpga 键盘防抖动模块设计
- FPGA 5 分频设计
- Java对象及其引用
- Oracle卸载
- 预测2009最可能流行的50句话
- 调查网赚应该注意的地方