相关疑难解决方法(0)

如何在Nunit中调用WPF Dispatcher?

我想测试一个呈现具有数据字段值的文本块的应用程序.渲染完成后,我想获得实际的宽度和实际高度.一切正常.当我尝试测试应用程序时,首先出现问题.我无法从测试项目中调用调度程序.

以下是代码.

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 …
Run Code Online (Sandbox Code Playgroud)

c# wpf nunit dispatcher nunit-mocks

6
推荐指数
1
解决办法
3441
查看次数

标签 统计

c# ×1

dispatcher ×1

nunit ×1

nunit-mocks ×1

wpf ×1