【问题标题】:Size Discrepancy: Powershell ISE vs Batch Launcher大小差异:Powershell ISE 与 Batch Launcher
【发布时间】:2017-07-05 18:05:43
【问题描述】:

我有一个使用 XML 节点阅读器在 Powershell 中创建的 XAML GUI。当我在 ISE 中运行脚本时,我的所有控件都在我想要的位置。然后我创建了一个批处理文件来启动它:

Powershell.exe -STA -File "C:\Scripts\Study App\Core.ps1"

运行批处理文件后,我注意到 GUI 本身比在 ISE 中时更大,因此我的一些按钮未对齐。当我右键单击 ps1 文件并单击 Run with Powershell 时,我也注意到了这种行为。 ISE 导致窗口尺寸变小的原因是什么?我有办法解决这个问题吗?

有一个几乎相同的问题here,但有一个显着的区别:我的表单是 System.Windows.Window 类型的,并且没有 System 所需的属性。 Windows.Forms.Form 有。

【问题讨论】:

    标签: wpf windows powershell xaml


    【解决方案1】:

    PowerShell ISE 会加​​载使用直接 PowerShell 时未加载的其他库。我快速搜索并在另一个网站上发现了这个问题:

    [https://social.msdn.microsoft.com/Forums/en-US/56352ca7-3e6e-452a-a1c8-09ab65c07089/powershell-wpf-window-sizes-different-when-run-outside-of-ps-ise?forum=wpf][1]

    看来解决方案可能是使用 SizeToContent="WidthAndHeight"。

    【讨论】:

    • 这并没有解决问题。它仍然相差 5 到 10 个像素。
    • 据我所见,这可能是 ISE 已加载而 Powershell 未加载的程序集。 [appdomain]::currentdomain.getassemblies() | sort -property fullname | format-table fullname 将显示正在加载到 ISE 或 Powershell 中的程序集。我做了一个快速检查,只是一个普通的 Powershell 窗口加载了 25 个程序集,而 ISE 加载了 47 个程序集......
    • 您在脚本中调用了哪些程序集?
    • System.Windows.Forms System.Windows.Forms.DataVisualization System.Drawing PresentationFramework WindowsBase PresentationCore 但应该无关紧要,因为这些程序集是通过 ISE 以及通过批处理文件加载的。
    • 问题是 ISE 加载的程序集比仅运行 poweshell 脚本会运行更多。 ISE 加载 47 个组件。只运行一个普通的 powershell 会话只加载 25 个。因此,如果 ISE 中的某些内容与右键单击并在 Powershell 中运行 ps1 文件不同,那么您需要找到缺少的程序集并将其添加到您的脚本中。
    猜你喜欢
    • 2021-09-26
    • 2018-03-09
    • 1970-01-01
    • 2019-11-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-07
    相关资源
    最近更新 更多