TreeView
Allows you to display a hierarchy of nodes with parents and child.
<TreeView Name="tvwList"
Grid.Column=0
Grid.Row=0
VerticalAlignment="Stretch"
HorizontalAlignment="Stretch">
<TreeViewItem Header="one"/>
<TreeViewItem Header="two"/>
<TreeViewItem Header="three"/>
</TreeView>
System.Windows.Controls.TreeViewItem oTreeViewItem;
oTreeViewItem = new TreeViewItem();
oTreeViewItem.Header = "four";
this.tvwList.Items.Add(oTreeViewItem);
treeviewitem = (System.Windows.Controls.TreeViewItem) this.tvwName.SelectedItem
MouseLeftButtonDown
System.Windows.Control.TreeViewItem treeviewitem;
System.Windows.DependencyObject dependencyobject;
try
{
//identify which node as been selected
treeviewitem = e.Source as System.Windows.Controls.TreeViewItem;
dependencyobject = this.tvwXMLParts.InputHitTest(e.GetPosition(this.tvwXMLParts)) as System.Windows.DependencyObject;
if (dependencyobject is System.Windows.Controls.TextBlock)
{
//initiate the dragging
System.Windows.DragDrop.DoDragDrop(this.txtXMLPart,
this.tvwXMLParts.SelectedValue,
System.WIndows.DragDropEffects.Move);
e.Handled = true;
}
}
MouseRightButtonUp
System.Window.Controls.TreeViewItem treeviewitem;
//identify which node has been selected
treeviewitem = e.Source as System.Windows.Controls.TreeViewItem;
//displays the context menu
if (treeviewitem != null)
{
tvwXMLPartsContextMenu.PlacementTarget = this;
tvwXMLPartsContextMenu.IsOpen = true;
}
System.Windows.Controls.TreeViewItem treeviewitem = (System.Windows.Controls.TreeView)
SearchTreeView<System.Windows.Controls.TreeViewItem>
((System.Windows.DependencyObject)e.OriginalSource);
if (treeviewitem != null)
{
treeviewitem.IsSelected = true;
e.Handled = true;
}
© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext