Я новичок в WPF. У меня есть combobox, связанный с источником данных XML, определенным в Window.Resources.WPB combobox не показывает значения во время выполнения
Значения combobox показаны в дизайнере, но во время выполнения он остается пустым.
Я что-то упустил.
<Window x:Class="WpfExample4.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="xmlData">
<x:XData>
<customers>
<customer name="Customer 1">
<order desc="Big Order">
<orderDetail product="Glue" quantity="21" />
<orderDetail product="Fudge" quantity="32" />
</order>
</customer>
<customer name="Customer 2">
<order desc="First Order">
<orderDetail product="Mousetrap" quantity="4" />
</order>
</customer>
</customers>
</x:XData>
</XmlDataProvider>
</Window.Resources>
<Grid DataContext= "{Binding Source={StaticResource xmlData}, XPath=customers/customer}" Margin="4" >
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<!-- CUSTOMERS -->
<DockPanel Grid.Row="0">
<TextBlock DockPanel.Dock="Top" FontWeight="Bold" Text="Customers" />
<ComboBox IsSynchronizedWithCurrentItem="True" ItemsSource="{Binding}" >
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding [email protected]}" />
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
</DockPanel>
</Grid>
</Window>
Благодаря kmatyaszek, он работал. –
@ user3006203, поэтому вы должны принять ответ, прочитайте этот вопрос: http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work – kmatyaszek