PoshCode Archive  Artifact [4a70d08e3a]

Artifact 4a70d08e3a1d9d545ae9b5672f728f9dc135a473fce3d0656779aeace3aa1062:

  • File TreeView-Sample.ps1 — part of check-in [0373144083] at 2018-06-10 13:07:49 on branch trunk — TreeView (user: unknown size: 1025)

# encoding: ascii
# api: powershell
# title: TreeView Sample
# description: TreeView
# version: 0.1
# type: function
# license: CC0
# function: view-TextFiles
# x-poshcode-id: 2252
# x-archived: 2010-09-26T20:53:27
#
#
Add-Type -AssemblyName presentationframework 

function view-TextFiles ($dir = '.') {
 
  # Create WPF Form from XAML file and bind Controls to variables
    
  $path = Resolve-Path $dir
  $Form=[Windows.Markup.XamlReader]::Load([IO.File]::OpenText('c:\scripts\window.xaml').basestream) 
  $ListBox = $form.FindName('listBox')
  $RichTextBox = $form.FindName('richTextBox1')
  
  # Fill ListBox

  ls *.ps1 |% {
    $li = new-Object Windows.Controls.ListBoxItem
    $li.Content = $_.name
    $li.Tag= $_.fullname
    $listbox.Items.Add($LI)
  }
  
  # Add Handler to Read File
  
  $ListBox.add_MouseDoubleClick({
    $RichTextBox.SelectAll()
    $RichTextBox.Selection.Text = gc $this.Selecteditem.Tag
  })

  # Invoke Form 
  
  $Form.ShowDialog() | out-null
}