本文整理汇总了C#中System.Windows.Controls.TreeViewItem.BringIntoView方法的典型用法代码示例。如果您正苦于以下问题:C# TreeViewItem.BringIntoView方法的具体用法?C# TreeViewItem.BringIntoView怎么用?C# TreeViewItem.BringIntoView使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Controls.TreeViewItem
的用法示例。
在下文中一共展示了TreeViewItem.BringIntoView方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WalkTreeViewItem
public static bool WalkTreeViewItem(TreeView tree, TreeViewItem treeViewItem, object selectedValue)
{
if (treeViewItem.DataContext == selectedValue)
{
treeViewItem.SetValue(TreeViewItem.IsSelectedProperty, true);
treeViewItem.Focus();
treeViewItem.BringIntoView();
return true;
}
var itemsHostProperty = treeViewItem.GetType().GetProperty("ItemsHost", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
var itemsHost = itemsHostProperty?.GetValue(treeViewItem, null) as Panel;
if (itemsHost == null)
{
return false;
}
foreach (var item in itemsHost.Children.OfType<TreeViewItem>())
{
var oldExpanded = item.IsExpanded;
item.IsExpanded = true;
item.UpdateLayout();
if (WalkTreeViewItem(tree, item, selectedValue))
{
return true;
}
item.IsExpanded = oldExpanded;
}
return false;
}
示例2: CollapseEverythingBut
// Collapse all items in the treeview except for the supplied item. The supplied item
// is also expanded, selected and scrolled into view.
private void CollapseEverythingBut(TreeViewItem item)
{
if (item != null)
{
DeepCollapse((TreeViewItem)treeView.Items[0]);
ExpandPathTo(item);
item.IsSelected = true;
item.BringIntoView();
}
}
示例3: JumpToNode
/// <summary>
/// Expand a TreeView to a specific node
/// </summary>
/// <param name="TreeViewItem">Searching will begin from this TreeViewItem</param>
/// <param name="NodeName">the name of the target node</param>
bool JumpToNode(TreeViewItem tvi, string NodeName)
{
bool jumped = false;
if (tvi.Name == NodeName)
{
tvi.IsExpanded = true;
tvi.BringIntoView();
tvi.IsSelected = true;
return true;
}
else
tvi.IsExpanded = false;
if (tvi.HasItems)
{
foreach (var item in tvi.Items)
{
TreeViewItem temp = item as TreeViewItem;
jumped = JumpToNode(temp, NodeName);
if (jumped)
break;
}
}
return jumped;
}
示例4: SelectEntry
private void SelectEntry(string remainingSelectPath, BackgroundStorageDirectory currentNode, TreeViewItem currentContainer)
{
var i = remainingSelectPath.IndexOf('\\');
if (i >= 0)
{
string next = remainingSelectPath.Substring(0, i);
remainingSelectPath = remainingSelectPath.Substring(i + 1);
currentNode = currentNode.Directories.First((dir) => dir.Name == next);
currentContainer = currentContainer.ItemContainerGenerator.ContainerFromItem(currentNode) as TreeViewItem;
currentContainer.IsExpanded = true;
currentContainer.ItemContainerGenerator.StatusChanged += (sender, args) =>
{
if (currentContainer.ItemContainerGenerator.Status == System.Windows.Controls.Primitives.GeneratorStatus.ContainersGenerated)
SelectEntry(remainingSelectPath, currentNode, currentContainer);
};
}
else
{
imageListView.SelectedItem = currentNode.Files.Where(file => file.Name == remainingSelectPath).SingleOrDefault();
currentContainer.IsSelected = true;
currentContainer.BringIntoView();
imageListView.Focus();
}
}
示例5: SelectItem
public void SelectItem(TreeViewItem item)
{
item.Focus();
item.IsSelected = true;
item.BringIntoView();
}
示例6: DragOverOrDrop
/// <summary>
/// First determine whether the drag data is supported.
/// Second determine what type the container is.
/// Third determine what operation to do (only copy is supported).
/// And finally handle the actual drop when <code>bDrop</code> is true.
/// </summary>
/// <param name="bDrop">True to perform an actual drop, otherwise just return e.Effects</param>
/// <param name="sender">DragDrop event <code>sender</code></param>
/// <param name="e">DragDrop event arguments</param>
private void DragOverOrDrop(bool bDrop, object sender, DragEventArgs e)
{
string[] files = this.GetData(e) as string[];
if(files != null) {
e.Effects = DragDropEffects.None;
ItemsControl dstItemsControl = sender as ItemsControl; // 'sender' is used when dropped in an empty area
if(dstItemsControl != null) {
foreach(string file in files) {
if(sender is TabControl) {
if(bDrop) {
TabItem item = new TabItem();
item.Header = System.IO.Path.GetFileName(file);
item.ToolTip = file;
dstItemsControl.Items.Insert(0, item);
item.IsSelected = true;
}
e.Effects = DragDropEffects.Copy;
}
else if(sender is ListBox) {
if(bDrop) {
ListBoxItem dstItem = Utilities.FindParentControlIncludingMe<ListBoxItem>(e.Source as DependencyObject);
ListBoxItem item = new ListBoxItem();
item.Content = System.IO.Path.GetFileName(file);
item.ToolTip = file;
if(dstItem == null)
dstItemsControl.Items.Add(item); // ... if dropped on an empty area
else
dstItemsControl.Items.Insert(dstItemsControl.Items.IndexOf(dstItem), item);
item.IsSelected = true;
item.BringIntoView();
}
e.Effects = DragDropEffects.Copy;
}
else if(sender is TreeView) {
if(bDrop) {
if(e.Source is ItemsControl)
dstItemsControl = e.Source as ItemsControl; // Dropped on a TreeViewItem
TreeViewItem item = new TreeViewItem();
item.Header = System.IO.Path.GetFileName(file);
item.ToolTip = file;
dstItemsControl.Items.Add(item);
item.IsSelected = true;
item.BringIntoView();
}
e.Effects = DragDropEffects.Copy;
}
else {
throw new NotSupportedException("The item type is not implemented");
}
// No need to loop through multiple
// files if we're not dropping them
if(!bDrop)
break;
}
}
e.Handled = true;
}
}
示例7: SelectAndShow
private void SelectAndShow(TreeViewItem tvi)
{
TreeViewItem parent = tvi.Parent as TreeViewItem;
while (parent != null)
{
parent.IsExpanded = true;
parent = tvi.Parent as TreeViewItem;
}
tvi.IsSelected = true;
tvi.BringIntoView();
// first try doesn't always bring it into view if we had to scroll a long way
Dispatcher.BeginInvoke(new ThreadStart(() => tvi.BringIntoView()), System.Windows.Threading.DispatcherPriority.Background);
}
示例8: UpdateItem
private void UpdateItem(TreeViewItem item)
{
bool is_executed = false, is_failed = false;
if (item.Tag is TestcaseView)
{
var testcase = item.Tag as TestcaseView;
is_executed = testcase.IsExecuted;
is_failed = testcase.Failed;
}
else if (item.Tag is TestFixtureView)
{
var fixture = item.Tag as TestFixtureView;
is_executed = fixture.AreAllExecuted;
is_failed = fixture.HasAnyFailures;
}
if (is_failed)
{
item.ExpandUpRecursive();
item.BringIntoView();
//((item.Header as StackPanel).Children[0] as Image).Source = red_icon;
//(item.Header as TextBlock).
item.Foreground = Brushes.Red;
//m_textbox2.Text = testcase.Exception.PrettyPrint();
//m_textbox1.Text = testcase.ToString() + " --> FAILED:\n\n" + testcase.Exception.Message;
//string s = testcase.Exception.PrettyPrint();
}
else if (is_executed)
{
item.Foreground = Brushes.Black;
}
else
item.Foreground = Brushes.DarkGray;
}
示例9: RecursivelySelectFolder
/// <summary>
/// Recursively loops through the treeview structure to get the correct
/// folder with the right path
/// </summary>
/// <param name="targetPath">Desired path</param>
/// <param name="tvItem">Current treeview item</param>
private static void RecursivelySelectFolder(TreeView treeView, string targetPath, TreeViewItem tvItem)
{
Folder thisFolder = tvItem.DataContext as Folder;
// We found this item - select it
if (targetPath.Equals(thisFolder.Path, StringComparison.CurrentCultureIgnoreCase) ||
targetPath.Equals(thisFolder.Path + "\\", StringComparison.CurrentCultureIgnoreCase))
{
tvItem.IsSelected = true;
tvItem.BringIntoView();
}
// We're on the right path, keep moving down a level
else if (targetPath.StartsWith(thisFolder.Path + (thisFolder.IsDrive ? "" : "\\"), StringComparison.CurrentCultureIgnoreCase))
{
thisFolder.ReadSubItemsForFolder();
tvItem.IsExpanded = true;
treeView.UpdateLayout();
foreach (Folder subFolder in tvItem.Items)
{
TreeViewItem subItem = tvItem.ItemContainerGenerator.ContainerFromItem(subFolder) as TreeViewItem;
RecursivelySelectFolder(treeView, targetPath, subItem);
}
}
else // This isn't it, break the tree
{
tvItem.IsExpanded = false;
treeView.UpdateLayout();
return;
}
}