我希望测试一款渲染带有数据字段值文本块的应用程序。我想在渲染完成后获得实际宽度和实际高度。一切都很顺利,但问题出现在我尝试测试该应用程序时。我无法从测试项目中调用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 and actual height.
}
));
};
我刚开始使用NUnit,希望你能帮助我。
谢谢