0
A
回答
0
尝试类似的东西:
XAML文件:
<Window x:Class="ComboBoxBindingXML.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="myData">
<x:XData xmlns="">
<Books>
<Book Title="Book1">
<Authors>
<Author Name="Make" Surname="Vey" />
<Author Name="Jane" Surname="McRoy" />
</Authors>
</Book>
<Book Title="Book2" />
<Book Title="Book3" />
<Book Title="Book4">
<Authors>
<Author Name="John" Surname="Rat" />
<Author Name="Dorian" Surname="Trust" />
</Authors>
</Book>
<Book Title="Book5" />
</Books>
</x:XData>
</XmlDataProvider>
</Window.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="30" />
<RowDefinition Height="10" />
<RowDefinition Height="30" />
<RowDefinition Height="10" />
<RowDefinition Height="30" />
<RowDefinition Height="10" />
<RowDefinition Height="30" />
</Grid.RowDefinitions>
<ComboBox Name="cbFirst" DataContext="{StaticResource myData}" ItemsSource="{Binding XPath=Books/Book }">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding [email protected]}" FontWeight="Bold" />
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
<ComboBox Name="cbSecond" Grid.Row="2" DataContext="{Binding ElementName=cbFirst, Path=SelectedItem}" ItemsSource="{Binding XPath=Authors/Author}">
<ComboBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding [email protected]}" FontWeight="Bold" />
<TextBlock Text=" " />
<TextBlock Text="{Binding [email protected]}" />
</StackPanel>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
<TextBlock Grid.Row="4" Text="{Binding ElementName=cbFirst, Path=Items.Count, UpdateSourceTrigger=PropertyChanged}" />
<TextBlock Grid.Row="6" Text="{Binding ElementName=cbSecond, Path=Items.Count, UpdateSourceTrigger=PropertyChanged}" />
</Grid>
</Window>
代码隐藏文件是空的。一切都发生在XAML文件中。
类XmlDataProvider有属性“源”,您可以在其中设置XML数据文件的Uri。
相关问题
- 1. 绑定组合框的DataSet在后面的代码(不XAML)
- 2. 数据绑定到一个组合框使用代码后面
- 3. 与字典对象绑定组合框,但后面未生效
- 4. WPF组合框数据绑定xaml与代码
- 5. c#ext.net:从后面的代码插入项目在组合框
- 6. 从后面的代码更新组合框SelectedItem
- 7. WPF XML数据绑定到组合框
- 8. 将组合框绑定到XML(wpf)
- 9. 用LINQ XML绑定组合框
- 10. 列表框与组合框DataTemplate绑定
- 11. WPF组合框如何绑定代码中的选定项目?
- 12. 绑定组合框
- 13. 绑定组合框
- 14. 组合框绑定
- 15. 组合框绑定
- 16. 后面的wpf绑定代码
- 17. Gridview绑定DropDownList后面的代码
- 18. 将组合框绑定到组合框
- 19. WPF组合框与枚举绑定
- 20. 与组合框将DataTable绑定在WPF
- 21. WPF:与组合框数据绑定
- 22. 多重绑定与组合框
- 23. WPF简单绑定在代码后面
- 24. 如何在后面的代码中绑定网格与属性?
- 25. 无法获得代码绑定为组合框工作
- 26. WPF组合框的SelectedItem绑定不从码
- 27. 如何从后面的C#代码更新WPF绑定的值?
- 28. 从后面的代码更改单向绑定的TextBlock值。
- 29. WPF如何设置复选框IsChecked在代码后面绑定
- 30. 帮助与组合框在JSP代码