我正在尝试自动化流畅的Ribbon控件(www.fluent.codeplex.com)。我成功地实现了大多数控件的自动化。但是,UI自动化工具无法识别或识别关闭,最大化和最小化按钮等问题,例如,使用Visual Studio进行编码UI测试。间谍工具不识别关闭,最大化,最小化等按钮。我无法通过自动化关闭应用程序(使用流畅的功能区)。
我正在查看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或名称放在关闭按钮中,或者为什么我可以解决问题的一些变化?唯一的要求是应用程序的Close,Maximize,Minimize按钮应由UI Automation工具识别。
此致
答案 0 :(得分:0)
这不会帮助您识别按钮,但您可以尝试将标准键盘快捷键发送到窗口以实际执行操作:
//close the window
Keyboard.SendKeys(myWindow, "{F4}", ModifierKeys.Alt);
答案 1 :(得分:0)
您可以尝试Automation Spy进行第二次检查。如果UI Automation没有给你任何东西,你可以尝试向控制窗口发送(参见SendMessage)Win32消息,如WM_CLOSE,你可以使用ShowWindow函数和参数SW_MAXIMIZE,SW_MINIMIZE。