我有一个带有组合框和几个文本框的表单。在我的XAML中,我按如下方式设置了一个资源:
<Window.Resources>
<DataTemplate x:Key="myTemplate">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Path=First}" />
<TextBlock Text=" " />
<TextBlock Text="{Binding Path=Last}" />
</StackPanel>
</DataTemplate>
</Window.Resources>
然后将该模板用于组合框
<ComboBox Name="theCombo"
IsSynchronizedWithCurrentItem="True"
ItemsSource="{Binding}"
ItemTemplate="{StaticResource myTemplate}" />
最后定义两个文本框如下
</Canvas.Resources>
<TextBlock Canvas.Top="5">First Name:</TextBlock>
<TextBox Canvas.Top="5" Text="{Binding Path=First}" />
<TextBlock Canvas.Top="25">Last Name:</TextBlock>
<TextBox Canvas.Top="25" Text="{Binding Path=Last}" />
</Canvas>
在代码中,我简单地定义了一个表适配器并将其用作数据上下文。
Dim dsTest As TestDataSet = New TestDataSet
Private Sub Window_Loaded(sender As Object, e As RoutedEventArgs)
Dim taEmployees As TestDataSetTableAdapters.EmployeesTableAdapter = New TestDataSetTableAdapters.EmployeesTableAdapter
taEmployees.Fill(dsTest.Employees)
DataContext = taEmployees
End Sub
我有两个问题。首先,虽然我可以确认taEmployees确实包含正确的数据,但组合框是空的。其次,我收到路径无效的两个文本框的错误消息。然而,相同的路径对myTemplate有效。
错误在哪里?