Search code examples
c#wpfmicrosoft-ui-automation

Is it possible to Click a label control on WPF/WinForm App using Microsoft Automation UI


On our application we have a clickable label which will pop up another window. I have been reading through the Microsoft Automation UI documentation, and can't find a way in which I'm able to click a label control.

I know that I can't use the Invoke Pattern as this only deals with Button controls.

Below is the code from the XAML that we have

 <Label Name="LblCompleteOrdersCount" Content="{Binding CompleteOrders, Mode=OneWay}" Margin="434,45,0,0" Height="62" Width="170" Padding="0" HorizontalAlignment="Left" VerticalAlignment="Top" VerticalContentAlignment="Top" FontSize="56" FontWeight="Bold">
    <Label.InputBindings>
        <MouseBinding Command="{Binding Path=CompleteOrdersCommand}" MouseAction="LeftClick" />
    </Label.InputBindings>
 </Label>

Solution

  • My hint is to use Button. It derives from ICommandSource interface and therefore you can effortlessly use Command to associate Button with handler. Ask yourself: what functionality does a Label provide that a Button does not? Better look? Override default Button's Template and you will get equivalent look. As long as you do not take advantage of any additional functionality of Label I see no point is messing around with it.