单项的绑定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的内容。界面并没有变化不知道是什么问题,希望知道的哥们指点一下。谢谢
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的内容。界面并没有变化不知道是什么问题,希望知道的哥们指点一下。谢谢
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货