WPF 命名空间问题 - 进程?

发布于 2024-07-09 16:56:29 字数 2038 浏览 8 评论 0原文

尝试从 http://www.munna.shatkotha.com/blog/post/2008/10/26/Light-box-effect-with-WPF.aspx

但是,我似乎无法理解下面“进程”的命名空间或语法权利。

<Border x:Name="panelDialog" Visibility="Collapsed">
<Grid>
<Border Background="Black" Opacity="0.49"></Border>
<!--While Xmal Content of the dialog will go here-->
</Grid>
</Border>

博文接着说......

只需放置两个隐藏和显示对话框的函数即可。 总代码如下。 在下面的代码中,我显示了带有灯箱效果的加载屏幕。 显示模式对话框时,只需调用显示和隐藏等待屏幕方法。 最好将 CPU 扩展作业发送到后台线程,并在后台线程中使用调度程序更新 UI。

<Page x:Class="Home">
<Grid>
<ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
<!--All the contents will go here-->
</ScrollViewer>
<Border x:Name="panelLoading" Visibility="Collapsed">
<Grid>
<Border Background="Black" Opacity="0.49"></Border>
<local:TMEWaitScreen></local:TMEWaitScreen>
</Grid>
</Border>
</Grid>
</Page>

代码

#region About Wait Screen
/// <summary>
/// Show wait screen before a web request
/// </summary>
public void ShowWaitScreen()
{
Process del = new Process(ShowWaitScreenUI);
Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, del);
}
private void ShowWaitScreenUI()
{
panelLoading.Visibility = Visibility.Visible;
}
/// <summary>
/// Hide a wait screen after a web request
/// </summary>
public void HideWaitScreen()
{
Process del = new Process(HideWaitScreenUI);
Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, del);
}
private void HideWaitScreenUI()
{
panelLoading.Visibility = Visibility.Collapsed;
}
#endregion

这是我在这一行中遇到问题的

Process del = new Process(ShowWaitScreenUI);

隐藏:我能找到的唯一进程是在 System.Diagnostics 中,并且不带任何参数。 我正在尝试学习的博客文章是否已关闭,或者我只是在错误的地方?

Trying to get this example working from http://www.munna.shatkotha.com/blog/post/2008/10/26/Light-box-effect-with-WPF.aspx

However, I can't seem to get the namespace or syntax right for "Process" below.

<Border x:Name="panelDialog" Visibility="Collapsed">
<Grid>
<Border Background="Black" Opacity="0.49"></Border>
<!--While Xmal Content of the dialog will go here-->
</Grid>
</Border>

The blog post goes on to say.....

Just put two function for hide and display the dialog. Total Code is given bellow. In bellow code I have Displayed a loading screen with light box effect. When displaying modal dialog just invoke show and hide wait screen methods. Its good to send your cpu expansive jobs to background thread and use dispatcher to update UI while you are in background thread.

<Page x:Class="Home">
<Grid>
<ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
<!--All the contents will go here-->
</ScrollViewer>
<Border x:Name="panelLoading" Visibility="Collapsed">
<Grid>
<Border Background="Black" Opacity="0.49"></Border>
<local:TMEWaitScreen></local:TMEWaitScreen>
</Grid>
</Border>
</Grid>
</Page>

Here is the codebehind

#region About Wait Screen
/// <summary>
/// Show wait screen before a web request
/// </summary>
public void ShowWaitScreen()
{
Process del = new Process(ShowWaitScreenUI);
Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, del);
}
private void ShowWaitScreenUI()
{
panelLoading.Visibility = Visibility.Visible;
}
/// <summary>
/// Hide a wait screen after a web request
/// </summary>
public void HideWaitScreen()
{
Process del = new Process(HideWaitScreenUI);
Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, del);
}
private void HideWaitScreenUI()
{
panelLoading.Visibility = Visibility.Collapsed;
}
#endregion

I'm having issues with this lines specifically:

Process del = new Process(ShowWaitScreenUI);

The only Process I can find is in System.Diagnostics, and takes no arguments. Is the blog post I'm trying to learn from off,or am I just in the wrong place?

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

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

发布评论

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

评论(2

渡你暖光 2024-07-16 16:56:29

看起来写博客的人忘记定义名为 Process 的自定义委托(这个名字有点奇怪)。

private delegate void Process();

现在应该可以编译它并定义它。

但我反而喜欢这些名字。

private delegate void HideWaitScreenHandler();
private delegate void ShowWaitScreenHandler();

实际上你可以重构它以使其变得更简单。

private delegate void ShowWaitScreenUIHandler(bool show);

void ShowWaitScreenUIThreaded(bool show)
{
    Process del = new ShowWaitScreenHandler(OnShowWaitScreenUI);
    Dispatcher.Invoke(DispatcherPriority.Normal, del, show);
}

void OnShowWaitScreenUI(bool show)
{
    panelLoading.Visibility = show ? Visibility.Visible : Visibility.Collapsed;
}

Looks like the person who wrote the blog forgot to define their custom delegate called Process (a bit of an odd name for it).

private delegate void Process();

It should compile now with it defined.

But I like these kind of names instead.

private delegate void HideWaitScreenHandler();
private delegate void ShowWaitScreenHandler();

Actually you can refactor this to make more simple.

private delegate void ShowWaitScreenUIHandler(bool show);

void ShowWaitScreenUIThreaded(bool show)
{
    Process del = new ShowWaitScreenHandler(OnShowWaitScreenUI);
    Dispatcher.Invoke(DispatcherPriority.Normal, del, show);
}

void OnShowWaitScreenUI(bool show)
{
    panelLoading.Visibility = show ? Visibility.Visible : Visibility.Collapsed;
}
爱冒险 2024-07-16 16:56:29

这里的拼写错误:Process 和 ShowWaitScreenHandler 需要更改为 ShowWaitScreenUIHandler。

DispatcherPriority 需要使用。 右键单击 DispatcherPriority 并选择“解决”。

Typos here: Process and ShowWaitScreenHandler needs to be changed to ShowWaitScreenUIHandler.

DispatcherPriority needs a using. Right click on DispatcherPriority and select Resolve.

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