【问题标题】:Binding Combobox to xml file problem将 Combobox 绑定到 xml 文件问题
【发布时间】:2011-08-16 20:52:53
【问题描述】:

这是我的xml

<Courses>

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

</Courses>

在我的 xaml 中我称之为:

 <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。有人知道我在做什么错吗?

【问题讨论】:

    标签: wpf xml mvvm binding combobox


    【解决方案1】:

    试试这个:

    <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" /> 
    

    【讨论】:

      猜你喜欢
      • 2011-04-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-11
      • 2011-07-05
      • 1970-01-01
      • 1970-01-01
      • 2010-09-22
      相关资源
      最近更新 更多