【发布时间】:2015-08-14 22:26:45
【问题描述】:
我有一个列表视图,其中包含具有 int ID 和字符串名称的对象。名称列是用户可编辑的文本框。如果用户更改了名称,我希望能够在列表中搜索具有相同 ID 的其他对象并更改这些名称。
我的大问题是,我想使用文本框的 LostFocus 属性来获取整个行或对象,而不仅仅是文本框。
下面的 XAML 已大大简化,但我认为它传达了基本思想:
<ListView x:Name="linkList"
<GridViewColumn Width="75">
<GridViewColumn.CellTemplate>
<TextBox Text="{Binding linkName}" LostFocus="TextBox_LostFocus"/>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Width="75">
<GridViewColumn.CellTemplate>
<TextBox Text="{Binding linkID}"/>
</GridViewColumn.CellTemplate>
</GridViewColumn>
所以在后面的代码中:
private void TextBox_LostFocus(object sender, RoutedEventArgs e)
{
//sender is the textbox in this case. so how
//would I get the object in that particular row so I can get its ID#?
}
我需要识别该特定行,因为用户可以单击不同的行或按“输入”来保存名称更改。因此,通过当前选定的行是不好的。有什么想法吗?
【问题讨论】: