示例#1
0
    public void SelectItem(TreeViewItem item)
    {
      SelectedItem = item;

      // Update IsSelected flags of all TreeViewItems. 
      foreach (var descendant in UIHelper.GetDescendants(this).OfType<TreeViewItem>())
        descendant.IsSelected = (descendant == item);
    }
示例#2
0
    // Called after the tree view control has processed device input.
    private void OnTreeViewInputProcessed(object sender, InputEventArgs eventArgs)
    {
      var treeView = (TreeView)sender;
      var selectedItem = treeView.SelectedItem;
      var inputService = treeView.InputService;

      if (!inputService.IsMouseOrTouchHandled               // Mouse was not handled before?
          && inputService.IsDoubleClick(MouseButtons.Left)  // Double-click detected?
          && selectedItem == _lastSelectedItem              // Both clicks were on the same item?
          && selectedItem != null                           // Any item is selected?
          && selectedItem.IsMouseOver)                      // The mouse is over the selected item?
      {
        // A tree view item was double-clicked. Show a message box with the data of the item.
        // This is only for debugging, so we simply use the Windows Forms MessageBox.
#if WINDOWS
        MessageBox.Show((string)selectedItem.UserData);
#endif
      }

      // Remember the selected item. This is necessary because we must be able to check if both
      // clicks of the double-click were on the same item. When a tree view item is clicked,
      // it is selected. Clicking two different items in rapid succession should not count as
      // a double-click.
      _lastSelectedItem = selectedItem;
    }