我正在尝试在选择中上下移动 TreeViewItem。尝试了所有在线论坛,但建议方式对我不起作用。任何人都可以帮忙。下面是我为Treecreation编写的代码。
XAML:
<TreeView Name="treeFileSystem" TreeViewItem.Selected="TreeViewItemSelected">
<TreeViewItem Header="Suite" Name="MYTree" Tag="hi" IsExpanded="True">
<TreeViewItem Name="treeFileSystem1" />
</TreeViewItem>
</TreeView>
CODE:
private void TestsTreeViewPageFunction_Loaded(object sender, RoutedEventArgs e)
{
this.MYTree.Items.Clear();
this.MYTree.ContextMenu = AddContexMenu("Suite");
for (int j = 1; j < 5; j++)
{
TreeViewItem Case = new TreeViewItem();
Case.ContextMenu = AddContexMenu("Case");
Case.Header = "Case "+j.ToString();
Case.IsExpanded = true;
for (int i = 0; i < 5; i++)
{
Case.Items.Add(Trythis(i));
}
this.MYTree.Items.Add(Case);
}
}
private TreeViewItem Trythis(int i)
{
TreeViewItem Step = new TreeViewItem();
Step.Header = "Steps " + i.ToString();
Step.ContextMenu = AddContexMenu("Step");
return Step;
}