WPF namespace question - Process?

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

However, I cannot get the namespace or syntax to be correct for the "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 goes on to say .....

Just put two functions to hide and show the dialog. The complete code is shown below. In the code below, I have displayed a loading screen with a light box effect. When displaying a modal dialog, just call the show and hide the idle screen methods. It's nice to send your extended jobs to a background thread and use a dispatcher to update the interface when you're on a 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 am having problems with these lines:

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 study or am I just in the wrong place?

0


source to share


2 answers


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



DispatcherPriority needs to be used. Right click on DispatcherPriority and select "Allow".

+1


source


It looks like whoever wrote the blog forgot to define their custom delegate called Process (a slightly odd name for it).

private delegate void Process();

      

It should now compile with the definition.

But I like these names.



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

      

You can actually refactor this to make it simpler.

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;
}

      

+2


source







All Articles