1

i'm really frustrated with this problem, but maybe it is really trivial and i just can't see where the problem is. The situation is the following: I have a ListView that is bound to an ItemsSource. Depending on the type, the DataTemplateSelector decides which template to use.

If i tab through the controls (textboxes) everything works fine. as soon as i enter a value in a textbox and tab out of the textbox propertychanged for this property gets called. my controls get updated. That all is working fine, but here comes the problem: While the controls get updated, the focus does not move to the next tabstop but jumps to the ListView. How can i disable that? How can i get it to move the focus like no data has been entered and property changed has not been raised?

Thanks in advance

Update: Part of the XAML, if you need further information please let me know

Update2: After setting Focusable=false on the ListView the focus now jumps out of the whole ListView control if PropertyChanged is raised

ListView declaration:

<ListView x:Name="ListViewFields"
            KeyboardNavigation.TabNavigation="Cycle" 
            KeyboardNavigation.IsTabStop="False"
            ItemsSource="{Binding Path=Fields}"                                           
            ItemTemplateSelector="{StaticResource ControlDataTemplateSelector}" 
            ItemContainerStyle="{StaticResource ListViewItemStyle}"
            Template="{StaticResource listViewTemplate}" 
            Grid.IsSharedSizeScope="true">
</ListView>

Example of an Template:

<DataTemplate x:Key="singleLineOfTextTemplate">
    <Grid Style="{StaticResource GridStyle}">
        <Grid.ColumnDefinitions>
            <ColumnDefinition SharedSizeGroup="MyFirstColumn" />
            <ColumnDefinition SharedSizeGroup="MySecondColumn" />
        </Grid.ColumnDefinitions>
        <Label Grid.Column="0" IsTabStop="False"
        Content="{Binding Path=Name}"
        />
        <TextBox  Grid.Column="1" x:Name="inputControl" IsTabStop="True"
        Text="{Binding Path=Value, Mode=TwoWay}"
        MinWidth="150"/>                 
    </Grid>
</DataTemplate>

Update 3: In the focus lost event of the ListViewItems I can see that focus is sometimes set to the DisconnectedItem (see DisconnectedItem on SO, may be this is a reason why I have this behavior.

I fixed my issue now by restoring the focus manually. In the ListViewItem GotFocus and LostFocus Events I store the selected ListViewItem and set a flag if restoring focus is neccessary, which then can be done in the ItemContainerGenerator.StatusChanged event.

This solution seems very ugly to me - any other suggestions or ways to fix this would still be nice.

Community
  • 1
  • 1
roqz
  • 1,020
  • 6
  • 17
  • post your XAML and code. Im too lazy to read your entire explanation. – Federico Berasategui Mar 14 '13 at 15:14
  • try setting CanFocus=false in your ListView – d.moncada Mar 14 '13 at 16:52
  • because ListView does not seem to have a CanFocus property I tried it with Focusable=false. Result: ListView does not get the focus anymore but instead focus is set completely out of the ListView and its elements and jumps to next control outside my ListView – roqz Mar 15 '13 at 08:03

0 Answers0