4

我正在尝试自动化流利的功能区控件(www.fluent.codeplex.com)。我成功地实现了大多数控件的自动化。但是有一个问题,例如关闭、最大化和最小化按钮无法被 UI 自动化工具识别或识别,例如,使用 Visual Studio 进行编码的 UI 测试。Spy 工具无法识别关闭、最大化、最小化等按钮。我无法通过自动化关闭应用程序(使用流利的功能区)。

我正在查看 RibbonWindow.xaml 中的以下代码部分

<StackPanel x:Name="PART_ButtonsPanel" HorizontalAlignment="Right" Margin="0,8,8,0" VerticalAlignment="Top" Orientation="Horizontal">
          <Button x:Name="minimizeButton" Style="{DynamicResource CaptionButtonStyle}" Width="35" Height="19" BorderThickness="1,0,0,1" Command="{x:Static Fluent:RibbonWindow.MinimizeCommand}">
            <Image Width="Auto" Height="Auto" HorizontalAlignment="Center" VerticalAlignment="Center" Stretch="None" Source="{DynamicResource ImageCaptionButtonMinimize}" SnapsToDevicePixels="True" RenderOptions.BitmapScalingMode="NearestNeighbor"/>
          </Button>
          <Button x:Name="maximizeButton" Margin="-1,0,0,0" Style="{DynamicResource CaptionButtonStyle}" Width="35" Height="19" BorderThickness="0,0,0,1" Command="{x:Static Fluent:RibbonWindow.MaximizeCommand}">
            <Image Width="Auto" Height="Auto" HorizontalAlignment="Center" VerticalAlignment="Center" Stretch="None" Source="{DynamicResource ImageCaptionButtonMaximize}" SnapsToDevicePixels="True" RenderOptions.BitmapScalingMode="NearestNeighbor"/>
          </Button>
          <Button x:Name="normalizeButton" Margin="-1,0,0,0" Style="{DynamicResource CaptionButtonStyle}" Width="35" Height="19" BorderThickness="0,0,0,1" Command="{x:Static Fluent:RibbonWindow.NormalizeCommand}">
            <Image Width="Auto" Height="Auto" HorizontalAlignment="Center" VerticalAlignment="Center" Stretch="None" Source="{DynamicResource ImageCaptionButtonNormalize}" SnapsToDevicePixels="True" RenderOptions.BitmapScalingMode="NearestNeighbor"/>
          </Button>
          <Button x:Name="closeButton" Margin="-1,0,0,0" Style="{DynamicResource CaptionButtonStyle}" Width="35" Height="19" BorderThickness="0,0,1,1" Background="Red" Command="{x:Static Fluent:RibbonWindow.CloseCommand}">
            <Image Width="Auto" Height="Auto" HorizontalAlignment="Center" VerticalAlignment="Center" Stretch="None" Source="{DynamicResource ImageCaptionButtonClose}" SnapsToDevicePixels="True" RenderOptions.BitmapScalingMode="NearestNeighbor"/>
          </Button>
        </StackPanel>

我尝试了很多东西(比如放置自动化 ID),但都没有奏效。我在看错误的代码部分吗?

有人可以帮助将自动化 UI 或名称放在关闭按钮中,或者通过为什么我可以解决问题进行一些更改?唯一的要求是应用程序的关闭、最大化、最小化按钮应由 UI 自动化工具识别。

问候

4

2 回答 2

0

这不会帮助您识别按钮,但您可以尝试将标准键盘快捷键发送到窗口以实际执行操作:

//close the window
Keyboard.SendKeys(myWindow, "{F4}", ModifierKeys.Alt);
于 2012-01-06T20:21:02.600 回答
0

您可以尝试Automation Spy进行第二次检查。如果 UI 自动化没有为您提供任何信息,您可以尝试将WM_CLOSE 等 Win32 消息发送(参见SendMessage )到控制窗口,您可以使用带有参数 SW_MAXIMIZE、SW_MINIMIZE 的ShowWindow函数。

于 2017-04-26T12:08:11.143 回答