I want to rename the treeitem on right click.
any suggestions
In my xaml I have <ControlTemplate x:Name="controlTreeItemTemplate" TargetType="Controls1:XamTreeItem"> <TextBox x:Name="ModifyText" LostFocus="ModifyTextLostFocus" Loaded="ModifyTextLoaded"></TextBox> </ControlTemplate>
in code behind
private ControlTemplate _Template; // Change the template to a textbox to allow the new report name to be // entered directly into the selected tree item. private void MenuRenameClick(object sender, EventArgs e) { //ReportTreeViewModel.MenuRename(); _Template = _RenameNode.Template; _RenameNode = ReportTreeViewModel.SelectedNode; _RenameNode.Template = controlTreeItemTemplate; }
// Rename Menu - Default the textbox to the current report name. private void ModifyTextLoaded(object sender, RoutedEventArgs e) { var modifytext = ((TextBox)sender); modifytext.Text = _RenameNode.Header.ToString(); modifytext.Focus(); modifytext.MaxLength = ReportGroupTreeViewHelper.IsReportNode(_RenameNode) ? 50 : 200; }
// Rename Menu private void ModifyTextLostFocus(object sender, RoutedEventArgs e) { // _RenameNode.Template = null; _RenameNode.Template = _Template; var tb = (TextBox)sender; ReportTreeViewModel.MenuRename(); }
when I am trying to set template back its throwing error and when I am setting template to null in ModifyTextLostFocus the node is disappearing.
any help will be appreciated.
Thanks