gpt4 book ai didi

wpf - 如何使用 teststack 获取 WPF TextBlock

转载 作者:行者123 更新时间:2023-12-02 02:00:44 26 4
gpt4 key购买 nike

我制作了一个 WPF 应用程序,并使用 teststack.white 进行了一些自动化测试。他们有关于如何将 Windows 中的控件映射到其框架的文档,但我在任何地方都没有看到 TextBlock。

他们的文档是 herehere .

谢谢

最佳答案

是的,你没有看错,那里没有提到 TextBlock

问题是 TextBlock 只是 WPF 中一个较长的 Label,您可以阅读 here :

A common understanding is that a Label is for short, one-line texts (but may include e.g. an image), while the TextBlock works very well for multiline strings as well, but can only contain text (strings).

因此您可以像使用标签一样获取它:

Application application = Application.Launch(applicationPath);
Window window = application.GetWindows().First();

var MyTextBlock = window.Get<Label>("MyTextBlock");

这是我用来测试它的 XAML 标记:

<Window x:Class="WpfApp1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApp1"
mc:Ignorable="d"
Title="MainWindow" Height="103.966" Width="191.724">
<Grid>
<TextBlock x:Name="MyTextBlock" Text="Hello!" Background="CornflowerBlue" Foreground="White" VerticalAlignment="Top"/>

</Grid>
</Window>

关于wpf - 如何使用 teststack 获取 WPF TextBlock,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50256159/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com