【发布时间】:2011-01-06 20:19:08
【问题描述】:
我有一个绑定到 XML 的 ListView。 XAML 如下所示:
<ListView Name="patientsListView" ItemsSource="{Binding}" SelectionChanged="patientsListView_SelectionChanged">
<ListView.View>
<GridView x:Name="patientGrid">
<GridViewColumn Header="PatientName" Width="Auto" DisplayMemberBinding="{Binding XPath=PatientName}" />
<GridViewColumn Header="PatientAccountNumber" Width="Auto" DisplayMemberBinding="{Binding XPath=PatientAccountNumber}" />
<GridViewColumn Header="DateOfBirth" Width="Auto" DisplayMemberBinding="{Binding XPath=DateOfBirth}" />
</GridView>
</ListView.View>
</ListView>
当点击一行时,我想做一些事情:
private void patientsListView_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
//do stuff
MessageBox.Show();
}
如果我单击一行,如何单独访问列中的值?调试时,我可以在 Listview SelectedItems 的 Locals 中看到我的数据在 Results View 的 InnerText 中的任何索引,但我不知道如何在代码中获取值。
【问题讨论】: