本文整理汇总了C#中System.Windows.Controls.TreeView.FindName方法的典型用法代码示例。如果您正苦于以下问题:C# TreeView.FindName方法的具体用法?C# TreeView.FindName怎么用?C# TreeView.FindName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Controls.TreeView
的用法示例。
在下文中一共展示了TreeView.FindName方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: getDirectories
/// <summary>
/// this is the function that maps the directories from the computer recursively
/// </summary>
/// <param name="directory"></param>
/// <param name="parentNode"></param>
/// <param name="tree"></param>
/// <param name="names"></param>
/// <returns></returns>
public TreeView getDirectories(DirectoryInfo directory, string parentNode, TreeView tree, ref List<string> names)
{
// TODO : Maybe the name of the treeviewitems should be the fullpath? that ensures its unique and we could later
// use the names (full paths) in order to find the file quickly for TFS stuff
// FIXED : have to pass the name of the parent node instead of using directory.Name because of the unique naming of the tree
// elements. by passing the unique name we can find the correct parent node
TreeViewItem parent = tree.FindName(parentNode) as TreeViewItem;
// gets down to last directory
DirectoryInfo[] dir = directory.GetDirectories();
if (dir.Length > 0)
{
foreach (DirectoryInfo subDir in dir)
{
// im just skipping over the git stuff for now. we can figure out how to deal with it later
if (!subDir.Name.Equals(".git"))
{
string header = subDir.Name;
string name = header.Split('.')[0];
// passes the name to a function that addes numbers to the end of the name to
// ensure the name is unique
name = uniqueName(name, ref names);
TreeViewItem item = new TreeViewItem() { Header = header, Name = name };
parent.Items.Add(item);
item.RegisterName(name, item);
names.Add(name);
getDirectories(subDir,name, tree, ref names);
}
}
}
//map files to current level of tree
FileInfo[] files = directory.GetFiles();
if (files.Length > 0)
{
foreach (FileInfo file in files)
{
string header = file.Name;
// this is more git stuff that we dont need to put in here but we might need to add more error stuff to catch weird
// names and such
if(header.Contains("git"))
{
header = header.Replace(".", "NotNeeded");
}
string name = header.Split('.')[0];
// passes the name to a function that addes numbers to the end of the name to
// ensure the name is unique
name = uniqueName(name, ref names);
TreeViewItem item = new TreeViewItem() { Header = header, Name = name };
parent.Items.Add(item);
item.RegisterName(name, item);
names.Add(name);
}
}
return tree;
}
示例2: addDataToTree
private void addDataToTree(TreeView treeView1, List<dynamic> actualList, List<dynamic> resultList, DBModule.TypeOfDepth depth, String value, int count)
{
// if (sendQuery != null)
// {
switch (depth)
{
case DBModule.TypeOfDepth.Section:
{
int i = count;
foreach (DBModule.Section sectionName in resultList)
{
if (!isAdded(actualList, sectionName, depth))
{
TreeViewItem mainItem = new TreeViewItem() { Header = "Section: " + sectionName.SectionName, Name = "item" + i };
treeView1.Items.Add(mainItem);
mainItem.RegisterName("regName" + i, mainItem);
i++;
}
}
break;
}
case DBModule.TypeOfDepth.ForumThread:
{
int i = count;
foreach (ForumThread forumThread in resultList)
{
if (!isAdded(actualList, forumThread, depth))
{
if (!dict.ContainsKey(forumThread.SectionName))
{
TreeViewItem mainItem = new TreeViewItem() { Header = "Section: " + forumThread.SectionName, Name = "item" + i };
treeView1.Items.Add(mainItem);
dict.Add(forumThread.SectionName, "regName" + i);
mainItem.RegisterName("regName" + i, mainItem);
TreeViewItem subItem = new TreeViewItem() { Header = "Thread: " + forumThread.ThreadName, Name = "subItem" + i };
mainItem.Items.Add(subItem);
subItem.RegisterName("regSubName" + i, subItem);
}
else
{
TreeViewItem searchItem = treeView1.FindName(dict[forumThread.SectionName]) as TreeViewItem;
TreeViewItem subItem = new TreeViewItem() { Header = "Thread: " + forumThread.ThreadName, Name = "subItem" + i };
searchItem.Items.Add(subItem);
subItem.RegisterName("regSubName" + i, subItem);
}
i++;
}
}
break;
}
case DBModule.TypeOfDepth.Post:
{
int i = count;
foreach (Post post in resultList)
{
if (!isAdded(actualList, post, depth))
{
if (!dictSections.ContainsKey(post.SectionTitle))
{
TreeViewItem mainItem = new TreeViewItem() { Header = "Section: " + post.SectionTitle, Name = "item" + i };
treeView1.Items.Add(mainItem);
dictSections.Add(post.SectionTitle, "regName" + i);
mainItem.RegisterName("regName" + i, mainItem);
if (!dictThreads.ContainsKey(post.TopicTitle))
{
TreeViewItem subItem = new TreeViewItem() { Header = "Thread: " + post.TopicTitle, Name = "subItem" + i };
mainItem.Items.Add(subItem);
dictThreads.Add(post.TopicTitle, "regSubName" + i);
subItem.RegisterName("regSubName" + i, subItem);
TreeViewItem postItem = new TreeViewItem() { Header = "Post: " + ChangeName(post.Content), Name = "postItem" + i };
subItem.Items.Add(postItem);
postItem.RegisterName("regPostName" + i, postItem);
}
else
{
TreeViewItem searchThreadItem = treeView1.FindName(dictThreads[post.TopicTitle]) as TreeViewItem;
TreeViewItem postItem = new TreeViewItem() { Header = "Post: " + ChangeName(post.Content), Name = "postItem" + i };
searchThreadItem.Items.Add(postItem);
postItem.RegisterName("regPostName" + i, postItem);
}
}
else
{
TreeViewItem searchItem = treeView1.FindName(dictSections[post.SectionTitle]) as TreeViewItem;
if (!dictThreads.ContainsKey(post.TopicTitle))
{
TreeViewItem subItem = new TreeViewItem() { Header = "Thread: " + post.TopicTitle, Name = "subItem" + i };
searchItem.Items.Add(subItem);
subItem.RegisterName("regSubName" + i, subItem);
TreeViewItem postItem = new TreeViewItem() { Header = "Post: " + ChangeName(post.Content), Name = "postItem" + i };
subItem.Items.Add(postItem);
postItem.RegisterName("regPostName" + i, postItem);
}
else
{
TreeViewItem searchThreadItem = treeView1.FindName(dictThreads[post.TopicTitle]) as TreeViewItem;
TreeViewItem postItem = new TreeViewItem() { Header = "Post: " + ChangeName(post.Content), Name = "postItem" + i };
searchThreadItem.Items.Add(postItem);
//.........这里部分代码省略.........