在 WPF 中渲染 TabItem(使用 powerhsell)

发布于 2024-09-27 01:04:04 字数 556 浏览 3 评论 0原文

可能是一个简单的问题,但我的大脑今天不工作。

我正在编写一个小型 powershell 脚本来执行各种任务。使用 WPF TabControl,这些任务在逻辑上分组为选项卡。

几个选项卡会执行一些检查以将本地文件日期与服务器文件日期进行比较,这需要一些时间。 (诚​​然,只有几秒钟,但这意味着在找到文件版本日期之前该选项卡不会呈现。)

因此,当脚本运行时,它会(快速)打开并显示第一个选项卡。然后,当选择每个选项卡时,我使用以下命令动态生成其余选项卡的内容:

$Tabs = $d.FindName('Tabs')
$Tabs.Add_SelectionChanged({ GenerateContent ($Tabs.SelectedItem).Header})

到目前为止,一切都很好,但就目前情况而言,当您选择这些选项卡之一时,它似乎在我的脚本运行时挂起它需要的信息。

我想要它做的是立即切换到选项卡,然后在获取信息时生成“请稍候..”,然后使用我需要的信息刷新页面。

谁能建议一个好方法来做到这一点?

Probably a simple question, but my brain isn't working today.

I am writing a small powershell script to do various tasks. These tasks are logically grouped into tabs, using a WPF TabControl.

A couple of the tabs do some checks to compare local file dates with server file dates, which takes a bit of time. (Only a few seconds, admittedly, but it means the tab doesn't render until the file version dates have been found.)

So - when the script is run, it opens (quickly) and displays the first tab. I then use the following to generate the content for the rest of the tabs on the fly when each tab is selected:

$Tabs = $d.FindName('Tabs')
$Tabs.Add_SelectionChanged({ GenerateContent ($Tabs.SelectedItem).Header})

So far, so good, but as it stands when you select one of these tabs it appears to hang while my script is getting the info it needs.

What I want it to do is to switch to the tab immediately, and then generate a "Please wait.." while it is getting the info, and then refresh the page with the info I need.

Can anyone suggest a good way of doing this?

Ta,

Ben

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

岁月染过的梦 2024-10-04 01:04:04

BackgroundWorker - 您需要的是在单独的线程上处理运行脚本,以便您的 UI 线程是空闲的,并且您可以显示“请稍候...”消息。执行完成后,您需要更新有关它的 UI。

请参考,
http://msdn.microsoft.com/en-us/library /system.componentmodel.backgroundworker.aspx

BackgroundWorker - What you need is to do processing of running the script on a separate thread so your UI thread is free and you can show the 'Please wait...' message. When the execution is complete you need to update the UI about it.

Please refer,
http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker.aspx

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文