I want editable root TreeViewItem, for that I create Event
<TreeView Height="182" Name="infoBox_treeview" Margin="0,2,0,182" BorderBrush="#FFA5A5A5" BorderThickness="2">
<TreeViewItem Header="t1"></TreeViewItem>
<TreeViewItem Header="t2">
<TreeViewItem Header="t21"></TreeViewItem>
<TreeViewItem Header="t22"></TreeViewItem>
</TreeViewItem>
<TreeViewItem Header="t3"></TreeViewItem>
<TreeView.ItemContainerStyle>
<Style TargetType="{x:Type TreeViewItem}">
<EventSetter Event="MouseDoubleClick" Handler="infobox_item_edit"></EventSetter>
</Style>
</TreeView.ItemContainerStyle>
<TreeView.ContextMenu>
<ContextMenu Name="infoBox_treeview_menu">
<MenuItem Header="Добавить ссылку" Name="infobox_menu_addlink" Click="infobox_menu_addlink_Click"></MenuItem>
<MenuItem Header="Удалить ссылку" Name="infobox_menu_dellink"></MenuItem>
</ContextMenu>
</TreeView.ContextMenu>
</TreeView>
In C#:
private void infobox_item_edit(object sender, RoutedEventArgs e)
{
var selItem=(TreeViewItem)this.infoBox_treeview.SelectedItem;
selItem.Header = new TextBlock() { Text = selItem.Header.ToString() };
}
But I have two problems:
1) This code doesn't change Header on TextBlock
2) This XAML set Event on all Items, I want edit only root items...
Thanks for help!