绑定组合框的xml文件的问题 [英] Binding Combobox to xml file problem

查看:158
本文介绍了绑定组合框的xml文件的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的XML

<Courses>

  <Course Name="Computerarchitectuur" />
  <Course Name="Frans" />
  <Course Name="Programmeren" />

</Courses>

在我的XAML我通过调用这个:

in my xaml i call this by:

 <XmlDataProvider x:Key="blabla"
                Source="C:\Users\Ruben\Desktop\Stage 26-04\stage_TFW\stage_TFW\NewWPFVragenBeheer\Data\Courses.xml"
                XPath="/Courses/Course"
           />



<ComboBox DataContext="{Binding Source={StaticResource blabla}}"  ItemsSource="{Binding XPath=@Name}" Height="23" HorizontalAlignment="Left" Margin="128,67,0,0" Name="comboBox1" VerticalAlignment="Top" Width="120" SelectionChanged="comboBox1_SelectionChanged" />

我的问题是,它只能显示第一要素,即Computerarchitectuur。没有人知道我在做什么错了?

My problem is, it only shows the first element, namely "Computerarchitectuur. DOes anyone know what i am doing wrong?

推荐答案

试试这个:

<XmlDataProvider x:Key="blabla" Source="C:\Users\Ruben\Desktop\Stage 26-04\stage_TFW\stage_TFW\NewWPFVragenBeheer\Data\Courses.xml" XPath="Courses/Course" />
<ComboBox ItemsSource="{Binding Source={StaticResource blabla}}" DisplayMemberPath="@Name" Height="23" HorizontalAlignment="Left" Margin="128,67,0,0" Name="comboBox1" VerticalAlignment="Top" Width="120" SelectionChanged="comboBox1_SelectionChanged" /> 

这篇关于绑定组合框的xml文件的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆