2016-11-16 66 views
0

Windows 7中,PowerShell的5傳遞變量爲XAML

在布魯斯·帕耶特的書「的Windows PowerShell在行動」(2)754頁上有一個名爲「建設文件搜索工具」一個WPF的例子。

我需要修改的XAML的ComboBox(原爲TextBox)在PowerShell中的變量$pwd[Environment]::GetFolderPath("MyDocuments")路過使用的東西 這樣的:

<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 

有沒有辦法做到這一點,請?

回答

0

您可以指定變量來定義XAML,像這樣:

<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> 
+0

非常感謝;但這不是解釋,即它顯示爲文字_ $ pwd_。 – Archdeacon