Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1192
Edit/Rename XamWebTreeItem
posted

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>

 

 

 

</ControlTemplate>

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.

Parents
No Data
Reply
  • 9694
    Suggested Answer
    posted

    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.

    Thanks!

Children