Using XamWebTree to populate folder structure and file name as leaf node.
I want to rename folder/file name (node.Header) .
I am populating tree dynamically by adding node (folder name & file name) to tree control. To edit any node (folder or file name), I am using ControlTemplate. This template
<ControlTemplate x:Name="controlTreeItemTemplate" TargetType="Ctl:XamWebTreeItem">
<TextBox x:Name="ModifyText" LostFocus="ModifyText_LostFocus" Loaded="ModifyText_Loaded"></TextBox>
On context menu rename click i am using following code to show template.
prevTemplate = selectedNode.Template ;
selectedNode.Template = controlTreeItemTemplate;
On ModifyText_LostFocus event, i reassign previous template.
selectedNode.Template =prevTemplate ; // Due to this statement i am getting error
selectedNode.Header = ModifyText.Text;
But it gives error.
Would please suggest how to avoid above error or achieve rename node funtionality.
Hello,
To ensure I provide a solution that best works with what you are doing, would you be willing to extract the relevant part of your code into a simple Silverlight sample? You can zip and attach the project to a response to this post (please first remove binaries and the xap file to make it smaller). I will add the fix to the sample.
Thanks!
I need the similar thing. My tree's data source is custom dto.
I want to right click tree item and change the name and than update my dto.
As soon as I am tabbing out the item its not showing anymore on the tree
can u please provide the example
It looks like you are trying to access in code a variable (x:Name) that is declared in the control template. The problem is control template names do not become variables in code. You must use the VisualTreeHelper to locate the item at run-time if you wish to access the item in code. You can also be clever about it - by using the Loaded event to get access to the item you wish to access (ModifyText). Another approach is to use TwoWay binding to a property in the tree. With ModifyText bound to that property, a change to it would change the data.
Let me know if you would like more help. Depending on the approach you wish to take, I could provide a sample that illustrates how to solve this.