How to put image “placemarkers” inside a scrollbar in WPF?

后端 未结 2 1467
栀梦
栀梦 2021-02-14 03:27

I have a long Scroll Viewer and I want to mark important spots with small images on the scroll bar. If the the image is clicked the scroll bar will jump to the corresponding con

2条回答
  •  轮回少年
    2021-02-14 04:00

    Short answer is "change the template of the ScrollBar".

    Long answer is... That I would add an ItemsControl in the template of the ScrollBar control. I would put this ItemsControl on top of the template with its IsHitTestVisible set to false so that it does not capture mouse events.

    Then I would use a Canvas as the ItemsPanelTemplate in order to be able to place the spots properly. I would use databinding with the ItemsSource property of the ItemsControl and a DataTemplate in order to render each element with an image.

    Here is a sample that I did using Blend. Of course it's not complete (it does not handle mouse event for example), but I hope it will be a starting point for you.


    (source: japf.fr)

    
        
            
                
                
                
            
            
            
                
                    
                
                
                    
                
                
                    
                
            
            
                10
                50
                100
                140
                
                    
                        
                    
                
                
                    
                                            
                
                    
                        
                    
                
            
            
        
    
    

提交回复
热议问题