2017-04-05 2 views
1

ToolBarでToggleButtonsを使用していますが、UI Automationテストで取得して使用したいのですが、これらのボタンのAutomationElement.Currentをチェックすると、WPFのAutomationElement ToggleButton - ClassNameボタンを持っています

<ToolBar ItemsSource="{Binding}"/> 

私はDataTemplateのを持っているのItemsSourceでの型のために:

<DataTemplate DataType="{x:Type myViewModelType}"> 
    <ContentPresenter Content="{Binding}" ContentTemplate="{StaticResource MyToolBarElementTemplate}"> 
     <ContentPresenter.Resources> 
      <Style TargetType="{x:Type ToggleButton}" BasedOn="{StaticResource ThisStyleSetsWidthAndHeight}"/> 
     </ContentPresenter.Resources> 
    </ContentPresenter> 
</DataTemplate> 
私はトグルボタン

は、XAMLがstarightforwardされていないので、私はそれをここに言及期待します

スタイルは次のように定義されています

<Style TargetType="{x:Type ButtonBase}" x:Key="ThisStyleSetsWidthAndHeight"> 
    <Setter Property="styles:AttachedProperties.ContentWidth" Value="32"/> 
    <Setter Property="styles:AttachedProperties.ContentHeight" Value="32"/> 
</Style> 

とコンテンツテンプレートは、次のようになります。

<DataTemplate x:Key="MyToolBarElementTemplate" DataType="{x:Type myViewModelType}"> 
    <ToggleButton x:Name="AutomationIdThatIGetOk"> 
     ... 
    </ToggleButton> 
</DataTemplate> 

私はそれがすべてのこれらのテンプレートとしなければならないと思い、オートメーションフレームワークに少し新しいですスタイルを使用できますが、このToggleButton用に作成された適切なAutomationPeerインスタンスを取得する方法はありますか?

答えて

1

...しかし、私は、これらのボタンのためAutomationElement.Currentをチェックしたときに、私はToggleButtonAutomationPeerクラスが実際にstring "を返すため、トグルボタン

はあなたの期待が間違っている期待される一方で、そのclassNameプロパティは、ボタンですボタン "GetClassNameCore()メソッドから:https://referencesource.microsoft.com/#PresentationFramework/src/Framework/System/Windows/Automation/Peers/ToggleButtonAutomationPeer.cs,a58abe77888c16cd

あなたは適切なインスタンスを取得しています。

+0

私は、HelpTextを使ってプロッパーボタンを識別し、それらのTogglePatternを使ってやりたいことをする – Myar

関連する問題