我有一个 xml 文件,我正在尝试将它绑定到标签但尚未成功,我使用 xmldataprovider 来绑定它。这是我使用的模板的代码。,我的 xml 文件中有几个任务,我是试图绑定第一个。
<Window.Resources>
<XmlDataProvider x:Key="TaskList" Source="http://store.tymesheet.com/templates/Graphic-Designer.xml" XPath="tasks"/>
<ControlTemplate x:Key="tasktemplate1">
<Canvas Height="40" Width="850">
<Label Content="{Binding XPath=task[1]}" Height="30" Width="170" Canvas.Top="5" Canvas.Left="150" Background="LightGray">
</Label>
<TextBox Height="30" Width="120" Canvas.Top="5" Canvas.Left="370" Background="AliceBlue"></TextBox>
<Label Canvas.Left="500" Canvas.Top="5">$</Label>
<Button Canvas.Top="8" Height="10" Width="30" Canvas.Left="600" ></Button>
</Canvas>
</ControlTemplate>
</Window.Resources>
并且使用模板的列表框的代码在这里
<TabItem>
<Canvas Height="700" Width="850">
<ListBox ItemsSource="{Binding Path=TaskList}" x:Name="listBox" Height="700" Width="850">
<ListBoxItem Template="{StaticResource tasktemplate1}"/>
</ListBox>
</Canvas>
</TabItem>
我没有找到我的绑定出错的地方,任何帮助,谢谢。