Question

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?

Was it helpful?

Solution

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

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

OTHER TIPS

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;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top