Using this question (Inline editing TextBlock in a ListBox with DataTemplate (WPF) I now have a listbox that can be doubleclicked to edit the items in it. What I want now is to have a button on the form, which when clicked will add a new item to the ListBox (this is easy), but then change the ListBoxItem into editmode, so the user can enter the value right away. How would you select the right ListBoxItem, and then find the TextBlock and TextBox inside it and change the visibility of them using the selectedIndex?
A:
I know this is a really late answer for this, but have you considered adding BeginEdit
and EndEdit
methods to your items? You could then do something like:
CustomListBoxItem foo = new CustomListBoxItem();
customListBoxInstance.Add(foo);
foo.BeginEdit();
I had to do that with a couple of my custom controls that needed to be created and immediately enter edit mode. You'd end up with something like:
private void TextBlock1_DoubleClick(object sender, RoutedEventArgs e)
{
BeginEdit();
}
public void BeginEdit()
{
// Code to put the item into edit mode.
}
I'd need to see some more code to give a more precise answer, but that's worked really well in my experience for controlling whether or not a control is in edit mode from outside the scope of that control.
md5sum
2010-09-10 21:06:22