wpf当单击按钮时,在列表框中编辑项目
问题描述:
使用this question (Inline editing TextBlock in a ListBox with DataTemplate (WPF)我现在有一个ListBox
可以双击来编辑它中的项目。我现在想要的是在窗体上有一个Button
,单击它时会将一个新项目添加到ListBox
(这很容易),但是然后将ListBoxItem
更改为editmode,以便用户可以立即输入该值。您如何选择合适的ListBoxItem
,然后在其中找到TextBlock
和TextBox
并使用SelectedIndex
更改它们的可见性?wpf当单击按钮时,在列表框中编辑项目
答
我知道这是一个非常晚的答案,但你有没有考虑过将BeginEdit
和EndEdit
方法添加到你的项目?然后,你可以这样做:
CustomListBoxItem foo = new CustomListBoxItem();
customListBoxInstance.Add(foo);
foo.BeginEdit();
我不得不这样做与将要创建的是需要几个我自定义控制,并立即进入编辑模式。你最终的东西,如:
private void TextBlock1_DoubleClick(object sender, RoutedEventArgs e)
{
BeginEdit();
}
public void BeginEdit()
{
// Code to put the item into edit mode.
}
我需要看到更多的代码,以提供更准确的答案,但是这真的很好在我的经验用于控制控件是否处于编辑来自该控制范围之外的模式。