gpt4 book ai didi

wpf - Powershell WPF StackPanel无法正确更新

转载 作者:行者123 更新时间:2023-12-02 23:51:53 25 4
gpt4 key购买 nike

我正在使用WPF XAML表单和Powershell [Windows.Markup.XamlReader]为Powershell UI启动页面编写一个“空闲启动屏幕”。

启动外部脚本时,启动页面进入“空闲”模式,即进入“空闲启动屏幕”的时间。

正常工作时的“怠速启动屏幕”示例:
enter image description here

现在的问题是:首次启动外部WPF UI(包括外部WPF Powershell脚本)时,“空闲启动屏幕”工作正常。但是,当关闭该外部WPF UI并重新打开另一个UI(仍在同一PSSession中)时,“空闲启动屏幕”看起来很奇怪。就像StackPanel一样,它的内部一直到前景,而忽略了任何不透明度或ZIndex设置(可以在下面的imgur链接中找到示例)。

我的WPF StackPanel:

    <StackPanel x:Name="Launching" Visibility="Visible">
<StackPanel.Background>
<LinearGradientBrush EndPoint="0.5,1" MappingMode="RelativeToBoundingBox" StartPoint="0.5,0">
<GradientStop Color="LightBlue" Offset="0.077"/>
<GradientStop Color="Transparent" Offset="2"/>
</LinearGradientBrush>
</StackPanel.Background>

<StackPanel Margin="0,180,0,0" Height="200" Width="200" Background="Transparent">
<wfi:WindowsFormsHost Margin="50,-30,0,0">
<winForms:PictureBox x:Name="pictureBoxLoading">
</winForms:PictureBox>
</wfi:WindowsFormsHost>
<Label Content="Applicatie lanceren..." Width="115" Margin="0,-29,0,0"/>
</StackPanel>
</StackPanel>

表格后面的Powershell代码:
## Loading the .gif
$pictureBoxLoading.Image = [System.Drawing.Image]::Fromfile("C:\Images\rocket.gif")

## Triggers
$Launching.Visibility = [System.Windows.Visibility]::Visible
$Launching.Visibility = [System.Windows.Visibility]::Hidden

我的问题的视频示例:
https://imgur.com/a/UZyxH0A

最佳答案

问题是由WindowsFormsHost引起的,因为它是WinForms对象,而不是WPF本身支持的。将其命名为(<wfi:WindowsFormsHost x:Name="Host"...)并将其隐藏。然后在其余的加载屏幕之后将其显示:

function hide {
$Launching.Visibility = [System.Windows.Visibility]::Hidden
$Host.Visibility = [System.Windows.Visibility]::Hidden
}

function show {
$Launching.Visibility = [System.Windows.Visibility]::Visible
$Host.Visibility = [System.Windows.Visibility]::Visible
}

关于wpf - Powershell WPF StackPanel无法正确更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57288112/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com