我有一个名为DataTable的names,其中有3列idnr、name、surname,我希望将从surname列中的所有行添加到WPFToolkit的AutoCompleteBox作为ItemsSource。
<toolkit:AutoCompleteBox x:Name="boxbox" Height="23"
ItemsSource="{Binding surname}"
SelectedItem="{Binding surname, Mode=TwoWay}" Margin="93,38,119,95" />发布于 2019-01-14 13:12:47
设置(boxbox.ItemsSource = dataTable.DefaultView;)或将ItemsSource属性绑定到DataTable的DefaultView,并定义一个ItemTemplate以显示姓氏列的值。还设置ValueMemberPath属性:
<toolkit:AutoCompleteBox x:Name="boxbox" Height="23"
ItemsSource="{Binding dt.DefaultView}"
ValueMemberPath="surname"
Margin="93,38,119,95">
<toolkit:AutoCompleteBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding surname}" />
</DataTemplate>
</toolkit:AutoCompleteBox.ItemTemplate>
</toolkit:AutoCompleteBox>如果绑定到ItemsSource,源属性应返回DataTable的DefaultView属性。还需要确保将AutoCompleteBox的AutoCompleteBox设置为定义源属性的类的实例。
https://stackoverflow.com/questions/54181795
复制相似问题