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 6215773
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T07:06:57+00:00 2026-05-24T07:06:57+00:00

In my application I have an Canvas wrapped in an ScrollViewer (Canvas is bigger

  • 0

In my application I have an Canvas wrapped in an ScrollViewer (Canvas is bigger then the screen size). On this canvas I have placed other controls. One of the elements on the canvas contains an virtualized DataGrid (with 2000+ rows … so ther is scrolling involved as well). Now I have a function that is selecting a row in the DataGrid based on some values of the row element (triggered automaticaly). When the row is selected, I call

uxDataGrid.ScrollIntoView(uxDataGrid.SelectedItems[0]);

what is working perfectly fine. As a matter of fact it is working way to good. What I want, is that the element in the DataGrid is selected and then the DataGrid should scroll to the correct position. But also my Canvas scrolviewer is somehow picking up this request and is scrolling there as well.

I already tried to intercept the ScrollChangedEvent and set the handled flag. But it is not working.

Qustions:

1) How can I limit the effect of the ScrollIntoView call to the local user control.

2) If that is not possible, how can I do the scrolling by myself? I would need to calculate the vertical offset for the scrollviewer, but since it is virtualized I have no idea how I can find out the row height?

Any suggestions?

I added a quick sample to demonstrate the principal setup. When hitting one of the buttons I want only the DataGrid to scroll, not the ScrollViewer continaing the canvas.

<Window x:Class="ScrollTest.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="350" Width="525">
<DockPanel>
    <StackPanel DockPanel.Dock="Bottom" Orientation="Horizontal">
        <Button Click="Button1_Click">Scroll to 1</Button>
        <Button Click="Button100_Click">Scroll to 100</Button>
        <Button Click="Button200_Click">Scroll to 200</Button>
    </StackPanel>
    <ScrollViewer>
        <Canvas Width="5000" Height="5000">
            <DataGrid Name="uxDataGrid" ItemsSource="{Binding TestItems}" Width="500" Height="500"></DataGrid>
        </Canvas>
    </ScrollViewer>
</DockPanel>

public class TestItem
{
    public TestItem(int id)
    {
        Property1 = id.ToString();
        Property2 = "B";
    }
    public string Property1 { get; set; }
    public string Property2 { get; set; }
}
/// <summary>
/// Interaktionslogik für MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
    public IList<TestItem> TestItems { get; set; }
    public MainWindow()
    {
        TestItems = new List<TestItem>();
        for ( int i = 0; i < 300; i++ )
        {
            TestItems.Add(new TestItem(i));
        }

        InitializeComponent();
        DataContext = this;
    }


    private void Button1_Click( object sender, RoutedEventArgs e )
    {
        uxDataGrid.ScrollIntoView( TestItems[0]);
    }
    private void Button100_Click( object sender, RoutedEventArgs e )
    {
        uxDataGrid.ScrollIntoView( TestItems[99] );
    }
    private void Button200_Click( object sender, RoutedEventArgs e )
    {
        uxDataGrid.ScrollIntoView( TestItems[199] );
    }
}
  • 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-24T07:06:58+00:00Added an answer on May 24, 2026 at 7:06 am

    Ok …after some research I found the correct event: It’s called RequestBringIntoViewEvent. When intercepting that one, it is working as expected:

    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            ...
            uxDataGrid.AddHandler( RequestBringIntoViewEvent, new RoutedEventHandler( HandleRequestBringIntoViewEvent ) );
        }
    
        private static void HandleRequestBringIntoViewEvent( object sender, RoutedEventArgs e )
        {
            e.Handled = true;
        }
        ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an application written in WPF with a ScrollViewer controlling a Canvas. This
In my Silverlight application I have Canvas control in ScrollViewer and lot of controls
On my application, I have a canvas which CSS size (CSS, not html) updates
I have this: <Canvas x:Name=LayoutRoot KeyDown=LayoutRoot_KeyDown> </Canvas> In a newly-minted Ag 3 application in
I have an application with two Canvas controls. When the application starts, it loads
this seems like a simple problem. I have a canvas application that I am
I have an html5 canvas drawing application similar to this http://jsfiddle.net/rnNFB/1/ , but using
I have a canvas in the middle of my application with controls around it.
In my WPF application I have a Canvas in which I do some drawing.
In My Application I Have ItemsControl with Canvas as ItemsPanelTemplate. Items of itemspanel source

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.