0

How to exclude TextBlock from tabbing sequence in SILVERLIGHT Grid XAML. I know for TextBox, we use IsTabStop false OR TabIndex -1, but same property is not avaiable for TextBlock

I have 4 controls, 1 and 4 are TextBox (editable) and 2 and 3 are TextBlock (non editable). When I tab, all the 4 are included in the tabbing sequence.

I want to exclude 2,3 (Textblocks) from tabbing. Means, If I tab from TextBox 1, focus should move directly to TextBox 4. please help.

Loaded="UserControl_Loaded">

              <DataTemplate x:Key="CellEditClientAllocations" >
                     <TextBox Text="{Binding ClientAllocations, Mode=TwoWay}" 
                     Style="{StaticResource GridCellTextBoxStyle}"                         
                     x:Name="tbxClientAllocations"
                     Loaded="TextBox_Loaded" 
                     TextChanged="tbxClientAllocations_TextChanged" 
                     KeyDown="tbxClientAllocations_KeyDown"
                     LostFocus="tbxClientAllocations_LostFocus"
                      GotFocus="tbxClientAllocations_GotFocus"/>
                </DataTemplate>
    <DataTemplate x:Key="CellAccountId">
                        <TextBlock Text="{Binding AccountId, Converter={StaticResource anc}}" Style="{StaticResource GridCellTextBlockStyle}" /> </DataTemplate>
    <DataTemplate x:Key="CellEditAccountId">           
            <TextBox  Text="{Binding AccountId, Converter={StaticResource anc}, Mode=TwoWay}" x:Name="tbxAccountId" LostFocus="TbxAccountIdLostFocus" TextChanged="TbxAccountIdTextChanged" GotFocus="tbxAccountId_GotFocus"/>
    </DataTemplate><DataTemplate x:Key="CellAccountName"> <StackPanel>
                <TextBlock  VerticalAlignment="Center" Text="{Binding AccountName, Mode=TwoWay}" Foreground="{Binding IsAccountValid, Converter={StaticResource cc}}"  kStyle="{StaticResource GridCellTextBlockStyle}" Name="Account" MouseRightButtonUp="" > </TextBlock> </StackPanel> </DataTemplate>       
    <DataTemplate x:Key="CellLotInstructions"> <StackPanel Orientation="Horizontal">
                <TextBlock Text="{Binding LotInstructions}" Style="{StaticResource GridCellTextBlockStyle}"/>
                <HyperlinkButton Content="Edit" Style="{StaticResource HyperlinkButtonStyleUnderline}" IsEnabled="{Binding LotInstructionsEnabled}" Name="Lotinstructons" HorizontalContentAlignment="Center" MouseLeftButtonDown="LotinstructonsMouseLeftButtonDown"  VerticalContentAlignment="Center" Click="ViewSpecifyLots_Click" Visibility="{Binding LotInstructionsEdit}" /> </StackPanel>  </DataTemplate>
user2235485
  • 1
  • 1
  • 3
  • 1
    How could texblock have focus..it is not possible .thats why there is no such focusable property for it. there must be something behind it..pardon me if i am wrong – Heena Jan 07 '14 at 14:35
  • Share your XAML, a `TextBlock` wouldn't receive focus by default so there has to be something else at play here. Do you maybe actually mean this in reference to `DataGrid` fields and not separate individual TextBlock's / TextBox's? – Chris W. Jan 07 '14 at 15:49
  • Thanks for your help. @Chris, textboxes and textblocks are in a DataGrid, not Separate textboxes/blocks. attached XAML. At the begining we have added – user2235485 Jan 08 '14 at 05:37
  • Ah ok, that explains a little better, you could use what @RohitVats said and apply it to the datagrid column (instead of a TextBlock like his example shows, but the fix of KeyboardNavigation.TabNavigation="None" is still correct) but sometimes that doesn't work for some reason and you would just apply the same thing via a setter in a CellStyle like seen [here](http://stackoverflow.com/questions/2111281/disable-tabstop-between-columns-in-a-wpf-datagrid) but of course edited for SL – Chris W. Jan 09 '14 at 19:09

3 Answers3

0

Try setting attached property KeyboardNavigation.TabNavigation to None.

<TextBlock KeyboardNavigation.TabNavigation="None"/>
Rohit Vats
  • 79,502
  • 12
  • 161
  • 185
0

Set Focusable="False" for the textblock

Arushi Agrawal
  • 619
  • 3
  • 10
0

I think you may need to work on the DataGrid Column rather than the Cell content (your TextBlock) it is the Cell that is Focussed not the TextBlock.

You could assign an event handler to the CellEnter Event (accessible from the definition of the original column) and then set the DataGrids selected cell selected property to false. Not the neatest solution but it should work.

Alternatively you could create a behaviour to do this....

Hope this helps!

Jason
  • 166
  • 3