0

Windows 7, PowerShell 5

In Bruce Payette's book "Windows Powershell In Action" (2) on page 754 there is a WPF example called "Building a file search tool".

I need to modify the ComboBox (originally a TextBox) in the XAML by passing in PowerShell variables $pwd and [Environment]::GetFolderPath("MyDocuments") by using something like:

<Label Width="100" >Path to Search</Label>
<ComboBox Name="Path" Width="324" Height="23" IsEditable="True">
    <ComboBoxItem >d:\files</ComboBoxItem>
</ComboBox>
$path = $form.FindName("Path")
$path.DropDown = $pwd

Is there a way to do this please?

Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
Archdeacon
  • 193
  • 1
  • 4
  • 15

1 Answers1

0

You can specify variable to XAML definition, like this:

 <Label Width="100" >Path to Search</Label>
       <ComboBox Name="Path" Width="324" Height="23" IsEditable="True">
          <ComboBoxItem >d:\files</ComboBoxItem>
          <ComboBoxItem >$pwd</ComboBoxItem>
          <ComboBoxItem >$([Environment]::GetFolderPath("MyDocuments"))</ComboBoxItem>
       </ComboBox>
Kirill Pashkov
  • 3,118
  • 1
  • 15
  • 20