6

I have a WPF Scrollviewer with its content as an Items Control which displays a list of images. I then have another scrollviewer with an Items control which hold the selected images. What I need to do is when some clicks the selected image, the item in the all images should scroll in to view.

I have searched around but couldn't find any examples of how to achieve this.

Anybody have any examples or suggestions?

1 Answer 1

15

you need to call bring into view on your SelectedItem's Container as such :

    var container = yourItemsControl.ItemContainerGenerator.ContainerFromItem(yourItemsControl.SelectedItem) as FrameworkElement;
    if (container != null)
        container.BringIntoView();

you should do this in a custom Behavior on selection changed.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the code, but I am having problems getting it to work. I have put the code in the MouseLeftDown event of the image, is this right?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.