How to get child element of default scrollbar(e.g. repeatbutton, thumb, etc.) in silverlight?

StackOverflow https://stackoverflow.com/questions/23101022

  •  04-07-2023
  •  | 
  •  

Question

I've listbox which has some collection binded & once the content size gets increased listbox gets vertical scrollviewer(default) visible. I got scrollbar from this scrollviewer as child element. But, when I'm trying to get child element (e.g. repeatbutton, thumb) from scrollbar then i get child element null. I got control hierarchy from silverlight spy. I want to get repeatbutton from vertical scrollabr(This is not custom scrollbar). For e.g. Code :

var objVRepeatBtn = ((FrameworkElement)VisualTreeHelper.GetChild(objvScrollBar, 0)).FindName("VerticalSmallIncrease") as System.Windows.Controls.Primitives.RepeatButton;

Any approach will be accepted.

Was it helpful?

Solution

I resolved this with approach like :

private RepeatButton rb = null;
private RepeatButton rb1 = null;
private Thumb thumb = null;

public ThumbnailUserControl()
{
  InitializeComponent();
  //sv1 repensented as ScrollViewer's object
  this.sv1.Loaded += new RoutedEventHandler(sv1_Loaded);
}

void sv1_Loaded(object sender, RoutedEventArgs e)
{
        FrameworkElement fe = VisualTreeHelper.GetChild(this.sv1, 0) as FrameworkElement;
        if (fe == null)
            return;
        var sb = fe.FindName("VerticalScrollBar") as ScrollBar;
        if (sb != null)
        {                
            thumb = (Thumb)((FrameworkElement)VisualTreeHelper.GetChild(sb, 0)).FindName("VerticalThumb");
            rb1 = (RepeatButton)((FrameworkElement)VisualTreeHelper.GetChild(sb, 0)).FindName("VerticalLargeDecrease");
            rb = (RepeatButton)((FrameworkElement)VisualTreeHelper.GetChild(sb, 0)).FindName("VerticalSmallIncrease");
            rb.Click += new RoutedEventHandler(rb_Click);
            thumb.DragCompleted += new DragCompletedEventHandler(thumb_DragCompleted);
            thumb.MouseWheel += new MouseWheelEventHandler(thumb_MouseWheel);
        }            
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top