listbox绑定XML文件(wpf)
五位数 2011-01-06 02:51:26 单项的绑定listbox是可以的代码如下
MainWindow.xaml文件
<Window x:Class="ListBoxBing.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<XmlDataProvider x:Key="MyTask" Source="Task.xml" XPath="/root"/>
</Window.Resources>
<Grid>
<ListBox Height="149" HorizontalAlignment="Left" Margin="114,66,0,0" Name="listBox1" VerticalAlignment="Top" Width="205" IsSynchronizedWithCurrentItem="True"
ItemsSource="{Binding Source={StaticResource MyTask},Mode=OneWay,
XPath=Task/@name}"
/>
<Button Content="Button" Height="46" HorizontalAlignment="Left" Margin="384,51,0,0" Name="button1" VerticalAlignment="Top" Width="76" Click="button1_Click" />
</Grid>
</Window>
Task.xml文件结构如下
<?xml version="1.0" encoding="utf-8"?>
<root>
<Task Nid="1" name="111"/>
<Task Nid="2" name="222"/>
<Task Nid="3" name="333"/>
<root>
现在我修改task.xml的内容。界面并没有变化
不知道是什么问题,希望知道的哥们指点一下。谢谢