Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7682881
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:40:10+00:00 2026-05-31T18:40:10+00:00

I’m developing a WPF app in which I have a ScrollViewer with grid (16

  • 0

I’m developing a WPF app in which I have a ScrollViewer with grid (16 ColumnDefinitions all auto width) with an image assigned to each column. The effect I want to create is when the mouse enters a area on the left of the ScrollViewer the images will scroll to the left… and when the mouse enters an area on the right of the ScrollViewer they scroll to the right. The scrollbars will be hidden. The areas to the left and right are defined by two rectangles with mouseEnter and mouseLeave events. My code behind utilises a timer to programatically scroll the ScrollViewer leftor right.

Here is my code…

Imports System
Imports System.IO
Imports System.Net
Imports System.Windows
Imports System.Windows.Controls
Imports System.Windows.Data
Imports System.Windows.Media
Imports System.Windows.Media.Animation
Imports System.Windows.Navigation


Partial Public Class Crime

    Dim ScrollLeft As Boolean = True
    Dim atimer As New System.Timers.Timer()

    Public Sub New()
        MyBase.New()

        Me.InitializeComponent()

        ' Insert code required on object creation below this point.

        ' Hook up the Elapsed event for the timer.
        AddHandler atimer.Elapsed, AddressOf Me.timer_Tick

        atimer.Interval = 100
        atimer.Enabled = True

    End Sub

    'CODE TO SCROLL SCROLLVIEWER PROGRAMATICALLY
    Private Sub timer_Tick(sender As Object, e As EventArgs)
        If ScrollLeft Then
            svImages.ScrollToHorizontalOffset(svImages.HorizontalOffset - 1)
        Else
            svImages.ScrollToHorizontalOffset(svImages.HorizontalOffset + 1)
        End If
    End Sub

    Private Sub Left_MouseEnter(sender As Object, e As MouseEventArgs)
        ScrollLeft = True
        atimer.Start()
    End Sub

    Private Sub Right_MouseEnter(sender As Object, e As MouseEventArgs)
        ScrollLeft = False
        atimer.Start()
    End Sub

    Private Sub Left_MouseLeave(sender As Object, e As MouseEventArgs)
        atimer.Stop()
        ScrollLeft = True
    End Sub

    Private Sub Right_MouseLeave(sender As Object, e As MouseEventArgs)
        atimer.Stop()
    End Sub

End Class

If I run this from Expressions Blend the project builds OK and displays, but the scroll action is not working.

If I run this from Visual Studio I get an error with the line…

svImages.ScrollToHorizontalOffset(svImages.HorizontalOffset - 0.1)

saying InvalidOperationException was unhandled by user code… The calling thread cannot access this object because a different thread owns it. I get this error before the window even loads.

Where have I gone wrong.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T18:40:11+00:00Added an answer on May 31, 2026 at 6:40 pm

    The error “The calling thread cannot access this object because a different thread owns it.” is quite standard for WinForms and WPF controls.

    In WPF and WinForms windows are rendered on the screen using one specific thread, usually called UI thread. Every update/change action regarding controls should take place on that thread to have success.

    Usual way to go with WinForms is to create a special delegate and call Control.Invoke as shown in this link.

    As of WPF, same effect is achieved with the use of a Dispatcher. Your code should look like this:

    this.Dispatcher.Invoke( () => svImages.ScrollToHorizontalOffset(svImages.HorizontalOffset - 0.1));
    

    UPDATE:

    I’ve got the following code to work in VB.NET:

    Private Delegate Sub ScrollDelegate(ByVal offset As Double)
    
    Private Sub ScrollLeft(ByVal offset As Double)
        svImages.ScrollToHorizontalOffset(svImages.HorizontalOffset + offset)
    End Sub
    
    // ... calling from background thread
    
    Dim slt As ScrollDelegate
    slt = New ScrollDelegate(AddressOf ScrollLeft)
    Me.Dispatcher.Invoke(slt)
    

    Update 2

    Code changed as to the question.

    Dim ScrollLeft As Boolean = True
    Dim atimer As New System.Timers.Timer()
    Dim scrollMethod As ScrollDelegate
    Private Delegate Sub ScrollDelegate(ByVal offset As Double)
    
    // ...
        Me.InitializeComponent()
        slt = New ScrollDelegate(AddressOf DoScroll)
    
    // ...
    
     Private Sub timer_Tick(sender As Object, e As EventArgs)
        If ScrollLeft Then
            Me.Dispatcher.Invoke(slt, -1)
        Else
            Me.Dispatcher.Invoke(slt, 1)
        End If
    End Sub
    
    // ...
    
    Private Sub DoScroll(ByVal offset As Double)
        svImages.ScrollToHorizontalOffset(svImages.HorizontalOffset + offset)
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a text area in my form which accepts all possible characters from
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I have a jquery bug and I've been looking for hours now, I can't
Basically, what I'm trying to create is a page of div tags, each has
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.