1
私は、小さなGUIを作成するためにWPFを使用するPowerShellスクリプトを作成しています。 TextBoxBase.TextChangedイベントを使用して、ComboBoxのテキストが変更されたときの検出を追加します。ここでPowerShellのComboBoxでTextBoxBase.TextChangedのハンドラを追加
は、私が試したいくつかのことです。
#Build the GUI; the next line has to NOT be indented
[xml]$xaml =
@"
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Name="Window" Title="Export Readable Prefs" WindowStartupLocation="CenterScreen"
Width="600" Height="200" ShowInTaskbar="True">
<DockPanel Margin="5">
<ComboBox Grid.Row="0" x:Name="ComboNewTemplate" IsEditable="true" />
</DockPanel>
</Window>
"@
$reader = (New-Object System.Xml.XmlNodeReader $xaml)
$Window = [Windows.Markup.XamlReader]::Load($reader)
$comboNewTemplate = $Window.FindName("ComboNewTemplate")
# this works
$comboNewTemplate.Add_SelectionChanged({Write-Host $_.AddedItems[0]})
# this doesn't
$comboNewTemplate.Add_TextBoxBase_TextChanged({Write-Host "text changed"})
# this doesn't, presumably because it hasn't been created yet
$textBox = $comboNewTemplate.Template.FindName("PART_EditableTextBox", $comboNewTemplate)
$textBox.Add_TextChanged({Write-Host "Text changed"})
# this doesn't; not even sure if this makes sense, it's out of my depth
function qwe(){"text changed"}
$func = qwe;
[System.Runtime.InteropServices.Marshal]::StructureToPtr($func, $intptr, $true)
$comboNewTemplate.AddHandler([System.Windows.Controls.Primitives.TextBoxBase]::TextChangedEvent, `
[System.Windows.RoutedEventHandler]::new($o1, $intptr))
$Window.ShowDialog()