Need Help make TextBlock visible for automation

Mar 3, 2010 at 3:59 PM

Hi

 

we have the same problem as described in WorkItem 11027

 

we have  an own class which extends TextBlock and we contained the described workaround but it does not work:

 

protected override AutomationPeer OnCreateAutomationPeer()
{
  return new CustomAutomationPeer(this);
}

public class CustomAutomationPeer : TextBlockAutomationPeer
{
  public CustomAutomationPeer(TextBlock textBlock)
	: base(textBlock)
  {
  }

  protected override bool IsContentElementCore()
  {
	return true;
  }
}

IsContentElementCore() seems to be never called 

here the xaml parts we use

<DataTemplate x:Key="dataTemplateTextCellDefault" DataType="{x:Type WpfToolkit:DataGridCell}"> 
    <MyTextBlock Text="{Binding Description}" /> 
  </DataTemplate>


<WpfToolkit:DataGridTextColumn x:Uid="WpfToolkit:DataGridTextColumn_7" Header="Date " IsReadOnly="True" Width="120" 
                                             Binding="{Binding Path=EntryDate, Converter={StaticResource dateConverter}, ConverterParameter=g, Mode=OneWay}" 
                                             Helper:CustomId.GridColumnId="ColumnDate" /> 
              <WpfToolkit:DataGridTextColumn x:Uid="textColumnUser" Header="User" IsReadOnly="True" Binding="{Binding Path=User, Mode=OneWay}" 
                                             Helper:CustomId.GridColumnId="ColumnUser" />
 <WpfToolkit:DataGridTextColumn x:Uid="textColumnUser" Header="User" IsReadOnly="True" Binding="{Binding Path=User, Mode=OneWay}" Helper:CustomId.GridColumnId="ColumnUser" /> <WpfToolkit:DataGridTemplateColumn x:Uid="textColumnDescription" Header="Description" IsReadOnly="True" CellTemplateSelector="{StaticResource logTemplateSelector}" Helper:CustomId.GridColumnId="ColumnDescription" />

the normal DataGridTextColumn are both visible the DataGridTemplateColumn not

Any idea??

Regards
Throndorin



 

 

Coordinator
Mar 3, 2010 at 7:05 PM

It should be

 

 protected override bool IsControlElementCore()
        {
            return true;
        }
This will make your custom TextBlock appear in the UIA tree. Also see my response here WorkItem 11027 for explanation. 

Mar 5, 2010 at 8:06 AM

many thanks now it works fine