我正在尝试将数据表的数据绑定到文本框。它工作正常,但它只显示数据表的最后一行。是否可以显示数据表的所有行?
XAML:
<Window x:Class="messenger.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" Loaded="Window_Loaded">
<Grid>
<TextBox Height="203" HorizontalAlignment="Left" Name="conversationInput" VerticalAlignment="Top" Width="491" Margin="12,3,0,0" IsReadOnly="True">
<TextBox.Text>
<MultiBinding StringFormat="{0} : {1}">
<Binding Path="date" />
<Binding Path="message" />
</MultiBinding>
</TextBox.Text>
</TextBox>
</Grid>
后面的代码:
public DataTable loadConversation()
{
DataTable conversation = new DataTable();
string loadMessages = "select message, date from Messages where userID=1";
ad = new MySqlDataAdapter(loadMessages, connection);
ad.Fill(conversation);
return conversation;
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
conversationInput.DataContext = loadConversation().DefaultView;
}
提前致谢, Fluxxi