Powershell-无法找到类型[System.Windows.Controls.TextBox]

问题描述 投票:0回答:1

我正在努力弄清为什么PS无法找到正确的程序集。我尝试了Add-Type和Reflection.Assembly的各种组合,但似乎没有什么改变。我觉得我在做一些根本错误的事情,但是我不知道下一步该怎么做。我也尝试过使用-LiteralPath参数并放置.dll文件的位置,但错误始终保持不变:“无法找到类型[System.Windows.Controls.TextBox]”]]。我在这里想念什么?

这在具有以下PS版本的Server2016上运行:

enter image description here

Add-Type -Name PresentationFramework
#Add-Type -Name System.Controls
#[void] [System.Reflection.Assembly]::LoadWithPartialName("PresentationFramework")
#[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Controls")
#[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") 
#[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") 

class TextBoxControl{

    [System.Windows.Controls.TextBox] $TextBox
    [String] $Name

    TextBoxControl ([String] $Name, [System.Windows.Controls.TextBox] $TextBox )
    {
        $This.TextBox = $TextBox
        $This.Name = $Name
    }


    [String] GetName(){
        Return $This.Name
    }

    [String] GetValue(){
        Return $This.TextBox.Text
    }

}

enter image description here

我正在努力弄清为什么PS无法找到正确的程序集。我尝试了Add-Type和Reflection.Assembly的各种组合,但似乎没有什么改变。我觉得我在做...

.net powershell assemblies
1个回答
0
投票

WinForms的TextBox命名空间引用是错误的,因为通过导入PresentationFramework(WPF),System.Windows.Forms(WinForms)的程序集将WPF与Windows窗体混合使用。

© www.soinside.com 2019 - 2024. All rights reserved.