How to invoke WPF Dispatcher in Nunit?

Posted by Reporting Avatar on Stack Overflow See other posts from Stack Overflow or by Reporting Avatar
Published on 2010-03-16T05:10:13Z Indexed on 2010/03/16 5:16 UTC
Read the original article Hit count: 647

Filed under:
|
|
|
|

I want to test an application which renders a text block with a data field value. I would like to get the actual width and actual height, once the rendering completes. Everything works fine. The problem came first, when I tried to test the application. I'm unable to invoke the dispatcher from the test project.

Following is the code.

        this.Loaded += (s, e) =>
            {
                TextBlock textBlock1 = new TextBlock();

                //// Text block value is assigned from data base field.
                textBlock1.Text = strValueFromDataBaseField;        
                //// Setting the wrap behavior.
                textBlock1.TextWrapping = TextWrapping.WrapWithOverflow;
                //// Adding the text block to the layout canvas.
                this.layoutCanvas.Children.Add(textBlock1);

                this.Dispatcher.BeginInvoke(DispatcherPriority.Background,
                    (Action)(() =>
                        {
                            //// After rendering the text block with the data base field value. Measuring the actual width and height.
                            this.TextBlockActualWidth = textBlock1.ActualWidth;
                            this.TextBlockActualHeight = textBlock1.ActualHeight;

                            //// Other calculations based on the actual widht and actual height.
                        }
                        ));
            };

I've just started using the NUnit. So, please help me.

Thanks

© Stack Overflow or respective owner

Related posts about c#

Related posts about wpf