# 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 }