views:

145

answers:

1

I have a custom control that is derived from ListView. This list view uses a GridView with two columns (each templated appropriately): one column is the caption (just a label) and the other column is the control.

When used, it looks like this:


<l:CoolList>
    <TextBox l:CoolList.Caption="Name" Text={Binding Name} />
    <TextBox l:CoolList.Caption="Age" Text={Binding Age} />
    <WrapPanel>
        <Button Click="btnOkay_click" />
        <Button Click="btnCancel_click" />
    </WrapPanel>
</l:CoolList>

This ends up looking something like this (everything is aligned nicely):

Name: [____________]
 Age: [____________]
      [Okay][Cancel]

Now, when I want to traverse these textboxes using TAB, it only focuses on the first textbox. To change focus to the other textboxes, I have to press CTRL+TAB.

I've looked through the MSDN website and it looks like I might need to implement an AutomationPeer but its really confusing what I'm supposed to do. Does anyone who has experience with this know how to make the child textboxes accessible (using just TAB)?

NOTE: The WPFToolKit datagrid is a good example of what I'm looking for. You can go through each grid item pressing TAB (not CTRL+TAB). They seem to implement AutomationPeers for the DataGrid, each row, each row presenter, each cell and each cell presenter. I'm looking for a generic solution where-by I can expose a control's children to TAB.

Question:

How do I make the ListView's items accessible to TAB (might be ListViewItem's children)?

A: 

As it turns out, there's a much simpler solution to this without re-implementing Automation Peers (since my custom list already has valid peers for its child items).

All I had to do was set this on my list's style:

<Setter Property="KeyboardNavigation.TabNavigation" Value="Cycle" />

See the Focus Overview page on MSDN for more information.

apandit