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代碼