我正在尝试通过在所选列表框项目的位置生成一个文本框来模拟列表框中的内联编辑。
我使用此函数来获取双击(选中)项:
void listBox_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
Control sourceControl = (ListBox)sender;
UIElement element = (UIElement)sourceControl.InputHitTest(e.GetPosition(sourceControl));
while(element != sourceControl)
{
if(element is ListBoxItem)
{
// reference to the selected item
ListBoxItem selectedItem = (ListBoxItem)element;
// the textbox
inlineTextEditBox.Visibility = System.Windows.Visibility.Visible;
inlineTextEditBox.Text = (string)((ListBoxItem)element).Content;
inlineTextEditBox.Focus();
return;
}
element = (UIElement)VisualTreeHelper.GetParent(element);
}
}
有人可以告诉我如何将文本框设置为所选项目吗?提前谢谢!