I am showing a list of images horizontally inside a scrolviewer and i am using the below line of code for doing it
<ScrollViewer Name="lviewThumbnails" Height="230" >
<ItemsControl ItemsSource="{Binding ThumbsCollection}" MouseWheel="ItemsControl_MouseWheel" >
<ItemsControl.ItemTemplate >
<DataTemplate>
<DockPanel Height="230">
<Button Name="pageThumbnail" DockPanel.Dock="Top" Tag="{Binding}" VerticalAlignment="Top" Margin="5,2">
<Grid>
<Image MaxWidth="140" Height="200" Source="{Binding ThubnailPath,IsAsync=True}" Stretch="None"></Image>
</Grid>
</Button>
<Label HorizontalAlignment="Center" FontSize="14" FontWeight="Bold" Content="text" Foreground="White" Padding="5"></Label>
</DockPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
I want to set the focus to a specific image item in this list when i opens the view For example if there are 150 images in the list and i want to set the focus to image 75 for instance while opening the list
What i am doing is on button click i am setting this code
lviewThumbnails.Visibility = Visibility.Visible;
to make the images visible , but very first item is the default selected one every time. I am using a trigger to detect the selected image as well like this
<DataTrigger Binding="{Binding IsSelected}" Value="True">
<Setter TargetName="pageThumbnail" Property="BorderBrush" Value="Yellow"/>
<Setter TargetName="pageThumbnail" Property="BorderThickness" Value="3"/>
</DataTrigger>
But the problem is if image 75 is the selected one i can see yellow border around image 75 , but focus is still on image 1 when i click the button.I have to previous , next buttons of scroll Viewer to reach to the image 75. I am using my scroll viewer with specific style like column 1 a button column 2 contents and column 3 again button ( Hope it doesn't affect default behavior) and i am preventing the mouse scroll on scroll viewer everywhere
<ControlTemplate TargetType="{x:Type ScrollViewer}" x:Key="ButtonOnlyScrollViewer">
<ControlTemplate.Resources>
</ControlTemplate.Resources>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="20" />
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="20"/>
</Grid.ColumnDefinitions>
<Button Style="{StaticResource ResourceKey=ViewPreviousButton}" Grid.Column="0" Command="ScrollBar.PageUpCommand" MouseWheel="ItemsControl_MouseWheel"
Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"></Button>
<ScrollContentPresenter
CanContentScroll="{TemplateBinding CanContentScroll}"
Grid.Column="1"
Content="{TemplateBinding Content}"
Width="{TemplateBinding Width}"
Height="{TemplateBinding Height}"
Margin="{TemplateBinding Margin}"/>
<Button Style="{StaticResource ResourceKey=ViewNextButton}" Grid.Column="2" Command="ScrollBar.PageDownCommand" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" MouseWheel="ItemsControl_MouseWheel"
></Button>
</Grid>
</ControlTemplate>