Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

How to edit a ListBox Item

$
0
0

I have a simple listbox of file names.   I have a button that I want to rename a file listed in the listbox.  

I have modified the default ListBoxItemStyle template and added a TextBox and made the visibility Collapsed.

<Grid><Border x:Name="Bd" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Padding="{TemplateBinding Padding}" SnapsToDevicePixels="true"><ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/></Border><TextBox Name="EditableText" Visibility="Collapsed"/></Grid>

When I press my button I want to be able to edit the text of the selected ListBox item.  When you press enter on the textbox I want the item to be changed.

I was thinking I could use the Tag property of the ListBoxItem and set it to true to show the textbox but I can't figure out how to do that or how to hide the textbox when the textbox has lost focus.

Any help?


Jeff Davis


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>