I have a virtualized ItemsControl with a list of either labels or textboxes. Virtualisation is needed because of the amount of data. Now i want tab through the liste with the keyboard. This works great until it reaches the end of the visible list. Than the focus leaves the list. Is there any way to "scroll" the list for the next focusable control? The problem is that not every item in the list has a focusable control.
Here is an example:
Is there any working solution? For example to load 10 more items as visible. Or find the last loaded focusable item and scroll by code. Or after showing the list laod all data in the background. RAM is not the bottleneck it is the rendertime of the list.
I have followed these Virtualizing an ItemsControl?
Here is the not working example
<ItemsControl DockPanel.Dock="Top" x:Name="lb" Height="200" ItemsSource="{Binding testList}"
KeyboardNavigation.TabNavigation="Cycle"
VirtualizingStackPanel.IsVirtualizing="True"
VirtualizingStackPanel.VirtualizationMode="Standard"
ScrollViewer.CanContentScroll="True"
AlternationCount="4"
>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel IsItemsHost="True" Orientation="Vertical" x:Name="virtualizingStackPanel" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBox Text="{Binding Path=., Mode=OneWay}" Name="txtTest">
<TextBox.Style>
<Style TargetType="TextBox">
<Setter Property="Visibility" Value="Collapsed" />
</Style>
</TextBox.Style>
</TextBox>
<Label >space</Label>
</StackPanel>
<DataTemplate.Triggers>
<Trigger Property="ItemsControl.AlternationIndex" Value="0">
<Setter Property="Visibility" Value="visible" TargetName="txtTest"/>
</Trigger>
</DataTemplate.Triggers>
</DataTemplate>
</ItemsControl.ItemTemplate>
<ItemsControl.Template>
<ControlTemplate>
<Border
BorderThickness="{TemplateBinding Border.BorderThickness}"
Padding="{TemplateBinding Control.Padding}"
BorderBrush="{TemplateBinding Border.BorderBrush}"
Background="{TemplateBinding Panel.Background}"
SnapsToDevicePixels="True">
<ScrollViewer
Padding="{TemplateBinding Control.Padding}"
Focusable="False" >
<ItemsPresenter
SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" Name="presenter"/>
</ScrollViewer>
</Border>
</ControlTemplate>
</ItemsControl.Template>
</ItemsControl>
Code Behind
public List<string> testList {
get
{
List< string> a = new List<string>();
for (int i = 0; i < 10000; i++)
{
a.Add(i.ToString());
}
return a;
}
}