开发者

How to synchronize two scroll viewers

开发者 https://www.devze.com 2023-03-11 08:57 出处:网络
I have a custom WPF control to display a list of items using an ItemsControl. The ItemsPresenter is defined in the template to display the list and it isembedded inside a ScrollViewer for scrolling pu

I have a custom WPF control to display a list of items using an ItemsControl. The ItemsPresenter is defined in the template to display the list and it is embedded inside a ScrollViewer for scrolling purposes:

<ControlTemplate TargetType="ItemsControl">
  <Grid x:Name="LayoutRoot">
    <ScrollViewer Margin="3">
       <ItemsPresenter/>
    </ScrollViewer>
  </Grid>
</Co开发者_如何转开发ntrolTemplate>

My application creates two instances of the custom control to show the list side by side.

What I want is when user selects an item on the first one, the second control automatically scrolls so that the same item is displayed in the same position relative to the top. To accomplish this I need to know

  1. How to get the position (in pixels) of the selected item in the first control?
  2. How to scroll to the same position in the second control?

Are there any other ways to do this?

0

精彩评论

暂无评论...
验证码 换一张
取 消