views:

1744

answers:

4

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?

+2  A: 

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;
}
John Z
A: 

Ah I see, and pardon my n00bness..... I have this in the codebehind now

    public Storyboard myStoryboard;
    public delegate void ShowWaitScreenUIHandler(bool show);

    public Window1()
 {
  this.InitializeComponent();

  // Insert code required on object creation below this point.
        myStoryboard = (Storyboard)TryFindResource("OnLoaded1");
        myStoryboard.Begin();
    }

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

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

Compile errors:

        Process del = new ShowWaitScreenHandler(OnShowWaitScreenUI);
        Dispatcher.Invoke(DispatcherPriority.Normal, del, show);

Error 1 The type or namespace name 'Process' could not be found (are you missing a using directive or an assembly reference?) C:\Users\John\Documents\Consulting\WaitIndicator\ucWaitIndicator\ucWaitIndicator\Window1.xaml.cs 37 13 ucWaitIndicator Error 2 The type or namespace name 'ShowWaitScreenHandler' could not be found (are you missing a using directive or an assembly reference?) C:\Users\John\Documents\Consulting\WaitIndicator\ucWaitIndicator\ucWaitIndicator\Window1.xaml.cs 37 31 ucWaitIndicator Error 3 The name 'DispatcherPriority' does not exist in the current context C:\Users\John\Documents\Consulting\WaitIndicator\ucWaitIndicator\ucWaitIndicator\Window1.xaml.cs 38 31 ucWaitIndicator Error 1 The type or namespace name 'Process' could not be found (are you missing a using directive or an assembly reference?) C:\Users\John\Documents\Consulting\WaitIndicator\ucWaitIndicator\ucWaitIndicator\Window1.xaml.cs 37 13 ucWaitIndicator Error 2 The type or namespace name 'ShowWaitScreenHandler' could not be found (are you missing a using directive or an assembly reference?) C:\Users\John\Documents\Consulting\WaitIndicator\ucWaitIndicator\ucWaitIndicator\Window1.xaml.cs 37 31 ucWaitIndicator Error 3 The name 'DispatcherPriority' does not exist in the current context C:\Users\John\Documents\Consulting\WaitIndicator\ucWaitIndicator\ucWaitIndicator\Window1.xaml.cs 38 31 ucWaitIndicator

John Batdorf
+1  A: 

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

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

John Z
A: 

Thanks! I see how this works now... Never really understood the use of a delegate before, very good stuff, thank you.

John Batdorf