本文整理汇总了C#中System.Windows.Controls.TreeViewItem.Focus方法的典型用法代码示例。如果您正苦于以下问题:C# TreeViewItem.Focus方法的具体用法?C# TreeViewItem.Focus怎么用?C# TreeViewItem.Focus使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Controls.TreeViewItem
的用法示例。
在下文中一共展示了TreeViewItem.Focus方法的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: SelectItem
public void SelectItem(TreeViewItem item)
{
item.Focus();
item.IsSelected = true;
item.BringIntoView();
}
示例3: SelectTreeViewItem
private bool SelectTreeViewItem(ref TreeViewItem rootNode, string elementName)
{
bool isSelected = false;
if (rootNode == null)
return isSelected;
if (!rootNode.IsExpanded)
{
rootNode.Focus();
rootNode.IsExpanded = true;
}
XmlNode tempNode = rootNode.Header as XmlNode;
if (tempNode == null)
{
return isSelected;
}
if (string.Compare(tempNode.Name, elementName, true) == 0)
{
rootNode.IsSelected = true;
rootNode.IsExpanded = true;
isSelected = true;
return isSelected;
}
else
{
for (int i = 0; i < rootNode.Items.Count; i++)
{
TreeViewItem childItem = rootNode.ItemContainerGenerator.ContainerFromIndex(i) as TreeViewItem;
isSelected = SelectTreeViewItem(ref childItem, elementName);
if (isSelected)
{
break;
}
}
return isSelected;
}
}
示例4: CreatePlaylist
/// <summary>
/// Creates a playlist track list and navigation items
/// </summary>
/// <param name="playlist">The data for the playlist to create</param>
/// <param name="select">Whether to select the playlist after it has been created</param>
private void CreatePlaylist(PlaylistData playlist, bool select = true)
{
Dispatcher.Invoke(DispatcherPriority.Background, new Action(delegate()
{
if (playlist.ListConfig == null)
{
ViewDetailsConfig vdc = SettingsManager.CreateListConfig();
SettingsManager.InitViewDetailsConfig(vdc);
vdc.HasNumber = true;
vdc.Sorts.Add("asc:Title");
vdc.Sorts.Add("asc:Track");
vdc.Sorts.Add("asc:Album");
vdc.Sorts.Add("asc:Artist");
if (SettingsManager.SearchPolicy == SearchPolicy.Global)
vdc.Filter = SettingsManager.FileListConfig.Filter;
else if (SettingsManager.SearchPolicy == SearchPolicy.Partial && SettingsManager.Playlists.Count > 1)
vdc.Filter = SettingsManager.Playlists[0].ListConfig.Filter;
playlist.ListConfig = vdc;
}
PlaylistTrackLists.Add(playlist.Name, null);
playlist.Tracks.CollectionChanged +=
new NotifyCollectionChangedEventHandler(PlaylistTracks_CollectionChanged);
// create the item in the navigation tree
TreeViewItem item = new TreeViewItem();
item.Selected += NavigationPane.Playlist_Selected;
item.Drop += NavigationPane.Playlist_Drop;
item.KeyDown += NavigationPlaylist_KeyDown;
item.Tag = playlist.Name;
item.Padding = new Thickness(8, 0, 0, 0);
item.HorizontalAlignment = HorizontalAlignment.Stretch;
item.HorizontalContentAlignment = HorizontalAlignment.Stretch;
DockPanel dp = new DockPanel();
dp.LastChildFill = false;
dp.HorizontalAlignment = HorizontalAlignment.Stretch;
Image img = new Image();
img.Source = Utilities.GetIcoImage("pack://application:,,,/Platform/Windows 7/GUI/Images/Icons/DiscAudio.ico", 16, 16);
img.Width = 16;
img.Height = 16;
img.Style = (Style)TryFindResource("HandHover");
dp.Children.Add(img);
EditableTextBlock etb = new EditableTextBlock();
etb.EnteredEditMode += new EventHandler(EditableTextBlock_EnteredEditMode);
etb.Text = playlist.Name;
etb.Margin = new Thickness(5, 0, 5, 0);
etb.Edited += NavigationPane.Playlist_Edited;
etb.Canceled += NavigationPane.Playlist_Canceled;
etb.HandHover = true;
dp.Children.Add(etb);
Image simg = new Image();
simg.Source = Utilities.GetIcoImage("pack://application:,,,/Platform/Windows 7/GUI/Images/Icons/Search.ico", 16, 16);
simg.Width = 16;
simg.Height = 16;
simg.Margin = new Thickness(5, 0, 5, 0);
simg.Visibility = Visibility.Collapsed;
DockPanel.SetDock(simg, Dock.Right);
dp.Children.Add(simg);
item.Header = dp;
item.ContextMenuOpening += new ContextMenuEventHandler(NavigationPane.Playlist_ContextMenuOpening);
item.ContextMenuClosing += new ContextMenuEventHandler(NavigationPane.Playlist_ContextMenuClosing);
item.ContextMenu = NavigationPane.playlistMenu;
NavigationPane.Playlists.Items.Insert(NavigationPane.Playlists.Items.Count - 1, item);
if (select)
item.Focus();
// create list context menu items
MenuItem miAdd = new MenuItem();
miAdd.Header = playlist.Name;
miAdd.Click += new RoutedEventHandler(listMenuAddToPlaylist_Click);
listMenuAddToPlaylist.Visibility = System.Windows.Visibility.Visible;
listMenuAddToPlaylist.Items.Insert(listMenuAddToPlaylist.Items.Count - 1, miAdd);
MenuItem miDel = new MenuItem();
miDel.Header = playlist.Name;
miDel.Click += new RoutedEventHandler(listMenuRemoveFromPlaylist_Click);
listMenuRemoveFromPlaylist.Visibility = System.Windows.Visibility.Visible;
listMenuRemoveFromPlaylist.Items.Add(miDel);
PlaybackControls.Search.AddPlaylist(playlist);
NavigationPane.SetSearchIndicator("Playlist:" + playlist.Name, playlist.ListConfig);
}));
}
示例5: FocusSelects
public virtual void FocusSelects()
{
TreeView view = new TreeView();
TreeViewItem first = new TreeViewItem { Header = "First" };
TreeViewItem second = new TreeViewItem { Header = "Second" };
view.Items.Add(first);
view.Items.Add(second);
TestAsync(
view,
() => first.Focus(),
() => Assert.IsTrue(first.IsSelected, "First should be selected!"),
() => second.Focus(),
() => Assert.IsTrue(second.IsSelected, "Second should be selected!"),
() => Assert.IsFalse(first.IsSelected, "First should not be selected now!"));
}
示例6: ExpanderButtonFocusActivatesSelection
public virtual void ExpanderButtonFocusActivatesSelection()
{
StackPanel root = new StackPanel();
TreeView view = new TreeView();
TreeViewItem item = new TreeViewItem { Header = "Item" };
Button button = new Button { Content = "Button" };
view.Items.Add(item);
root.Children.Add(view);
root.Children.Add(button);
ToggleButton ExpanderButton = null;
TestAsync(
5,
root,
() => item.Focus(),
() => Assert.IsTrue(item.IsSelected, "Item should be selected!"),
() => Assert.IsTrue(item.IsSelectionActive, "Selection should be active after focusing!"),
() => button.Focus(),
() => Assert.IsFalse(item.IsSelectionActive, "Selection should be inactive after focusing on something else!"),
() => ExpanderButton = item.GetVisualChild("ExpanderButton") as ToggleButton,
() => Assert.IsNotNull(ExpanderButton, "Failed to find template part ExpanderButton!"),
() => ExpanderButton.Focus(),
() => Assert.IsTrue(item.IsSelectionActive, "Selection should be active after focusing ExpanderButton!"));
}
示例7: SelectionInactiveOnLostFocus
public virtual void SelectionInactiveOnLostFocus()
{
StackPanel root = new StackPanel();
TreeView view = new TreeView();
TreeViewItem item = new TreeViewItem { Header = "Item" };
view.Items.Add(item);
Button other = new Button { Content = "Button" };
root.Children.Add(view);
root.Children.Add(other);
TestAsync(
root,
() => Assert.IsFalse(item.IsSelected, "Item should not be selected initially!"),
() => Assert.IsFalse(item.IsSelectionActive, "Item should not have inactive selection initially!"),
() => item.Focus(),
() => Assert.IsTrue(item.IsSelected, "Item should be selected after focus!"),
() => Assert.IsTrue(item.IsSelectionActive, "Item should not have inactive selection after focus!"),
() => other.Focus(),
() => Assert.IsTrue(item.IsSelected, "Item should be selected after focusing another element!"),
() => Assert.IsFalse(item.IsSelectionActive, "Item should have an inactive selection after focusing another element!"));
}
示例8: RefreshLayers
/// <summary>
/// Fetches the structure of the layers and layer group names (in an XML document format)
/// that are currently in the layer manager in WWT.
/// </summary>
/// <param name="displayResponse">show the response in response output</param>
/// <param name="isLayerCreated">Checks if the call has come from Create layer</param>
private void RefreshLayers(bool displayResponse, bool isLayerCreated)
{
try
{
string url = string.Format("http://{0}:5050/layerApi.aspx?cmd=layerlist", this.machineIp);
string payload = string.Empty;
string response = WWTRequest.Send(url, payload);
if (displayResponse)
{
this.PrintSendAndReceive(url, response);
this.PrintSendAndReceiveHeader("Refresh Layer List");
}
this.layersTree.Items.Clear();
XmlDocument doc = new XmlDocument();
doc.LoadXml(response);
XmlNode root = doc["LayerApi"];
XmlNode layersNode = root["LayerList"];
foreach (XmlElement element in layersNode.ChildNodes)
{
TreeViewItem node = new TreeViewItem();
node.Header = element.Attributes["Name"].Value;
node.Name = element.Name;
if (element.Attributes["ID"] != null)
{
node.Tag = element.Attributes["ID"].Value;
}
this.layersTree.Items.Add(node);
node.IsExpanded = true;
foreach (XmlElement child in element.ChildNodes)
{
// If the layer is not of spread sheet layer type, then ignore them.
if (child.Attributes["Type"] != null && !child.Attributes["Type"].Value.Equals("SpreadSheetLayer", StringComparison.OrdinalIgnoreCase))
{
continue;
}
TreeViewItem childNode = new TreeViewItem();
childNode.Header = child.Attributes["Name"].Value;
childNode.Name = child.Name;
if (child.Attributes["ID"] != null)
{
childNode.Tag = child.Attributes["ID"].Value;
}
node.Items.Add(childNode);
// Select Earth.
if (childNode.Header.ToString().Equals("Earth", StringComparison.OrdinalIgnoreCase) && !isLayerCreated)
{
childNode.IsSelected = true;
}
foreach (XmlElement grandChild in child.ChildNodes)
{
// If the layer is not of spread sheet layer type, then ignore them.
if (grandChild.Attributes["Type"] != null && !grandChild.Attributes["Type"].Value.Equals("SpreadSheetLayer", StringComparison.OrdinalIgnoreCase))
{
continue;
}
TreeViewItem grandChildNode = new TreeViewItem();
grandChildNode.Header = grandChild.Attributes["Name"].Value;
grandChildNode.Name = grandChild.Name;
if (grandChild.Attributes["ID"] != null)
{
grandChildNode.Tag = grandChild.Attributes["ID"].Value;
if (isLayerCreated)
{
if (grandChild.Attributes["ID"].Value == layerId)
{
grandChildNode.IsSelected = true;
layersTree.Focus();
grandChildNode.Focus();
childNode.IsExpanded = true;
}
}
}
childNode.Items.Add(grandChildNode);
foreach (XmlElement greatGrandChild in grandChild.ChildNodes)
{
// If the layer is not of spread sheet layer type, then ignore them.
if (greatGrandChild.Attributes["Type"] != null && !greatGrandChild.Attributes["Type"].Value.Equals("SpreadSheetLayer", StringComparison.OrdinalIgnoreCase))
{
continue;
}
TreeViewItem greatGrandChildNode = new TreeViewItem();
greatGrandChildNode.Header = greatGrandChild.Attributes["Name"].Value;
greatGrandChildNode.Name = greatGrandChild.Name;
if (greatGrandChild.Attributes["ID"] != null)
//.........这里部分代码省略.........
示例9: HandleItemChanged
private void HandleItemChanged (TreeViewItem tvi, WatchViewModel node)
{
if (tvi == null || node == null)
return;
// checks to see if the node to be selected is the same as the currently selected node
// if so, then de-select the currently selected node.
if (node == prevWatchViewModel)
{
this.prevWatchViewModel = null;
if (tvi.IsSelected)
{
tvi.IsSelected = false;
tvi.Focus();
}
}
else
{
this.prevWatchViewModel = node;
}
if (_vm.FindNodeForPathCommand.CanExecute(node.Path))
{
_vm.FindNodeForPathCommand.Execute(node.Path);
}
}