我有一个名为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
复制相似问题