Hello!
I’m facing some issue with ValueChanged event handler of a slider control element in my WPF script, generated in Visual Studio Community 2017 with PowerShell Pro Tools with a trial license. Here is my simple xaml
"
"
and my xaml.ps1 file
function Add-ControlVariables {
New-Variable -Name ‘sldr_hTime’ -Value $window.FindName(‘sldr_hTime’) -Scope 1 -Force
}
[System.Reflection.Assembly]::LoadWithPartialName(“PresentationFramework”) | Out-Null
function Import-Xaml {
[xml]$xaml = Get-Content -Path $PSScriptRoot\WpfWindow1.xaml
$manager = New-Object System.Xml.XmlNamespaceManager -ArgumentList $xaml.NameTable
$manager.AddNamespace(“x”, “http://schemas.microsoft.com/winfx/2006/xaml”);
$xaml.SelectNodes("//*[@x:Name=‘sldr_hTime’]", $manager)[0].RemoveAttribute(‘ValueChanged’)
$xamlReader = New-Object System.Xml.XmlNodeReader $xaml
[Windows.Markup.XamlReader]::Load($xamlReader)
}
function Set-EventHandler {
$sldr_hTime.add_ValueChanged({
param([System.Object]$sender,[System.Windows.RoutedPropertyChangedEventArgs`1[System.Double`ValueType]]$e)
Set_txbx_hTime -sender $sender -e $e
})
}
$window = Import-Xaml
Add-ControlVariables
Set-EventHandler
function Set_txbx_hTime
{
param($sender, $e)
}
$window.ShowDialog()
No single line of manually typed code-behind. Absolutely everything is automatically generated by the PoSh Tools Extention. But when I run my application, while trying to moove the slider’s thumb (changing the value property) I get a runtime exception
[ERROR] Exception calling “ShowDialog” с “0” arguments: “Type not found [Sy
[ERROR] stem.Double`ValueType].” =(((((
The only place this could be found in .ps1 is “param([System.Object]$sender,[System.Windows.RoutedPropertyChangedEventArgs1[System.Double
ValueType]]$e)” but am not aware of this construct. As far as I know, System.Windows.RoutedPropertyChangedEventArgs and System.Double are the .Net Framework classes and the ValueType is as well. But what does the whole construct “[System.Windows.RoutedPropertyChangedEventArgs1[System.Double
ValueType]]” means?
How can I handle the ValueChanged event of my slider? As far as I get, without handling this event the whole Control Element is useless if I can’t get what value a user have chosen.
What am I missing? Or its better to say WTF with WPF?))))