Topic Author
Posts: 113
Joined: 30 Jul 2018, 05:03

Can't get Thumb from Slider when upgrading to 3.0

29 May 2020, 11:44

Before upgrading I got a Thumb from a Slider like this:
Loaded += (s, e) =>
                var thumb = (Thumb)uiScaleSlider.GetTemplateChild("SliderThumb");
Now it just returns null.
User avatar
Site Admin
Posts: 2097
Joined: 22 Dec 2011, 19:20

Re: Can't get Thumb from Slider when upgrading to 3.0

29 May 2020, 12:03

Are you using our new theme in 3.0 for your controls or have you created your own?

GetTemplateChild method looks for a named element in the template's visual tree, so depending on what ControlTemplate you are using in your Slider it would return a valid element or not.

For example, the Slider's template in our theme looks like this:
<ControlTemplate x:Key="Template.Slider.Horizontal" TargetType="Slider">
    <Grid x:Name="TemplateRoot" Height="20" Margin="8,0">
      <Track x:Name="PART_Track" Grid.RowSpan="3" Orientation="Horizontal">
          <Thumb x:Name="Thumb" Background="{TemplateBinding Foreground}" Style="{StaticResource Style.Slider.Thumb}"/>
As you can see the Thumb element is named "Thumb" there, but it could also have no name or have any other name, there are no constraints for that. If your code looks for a named element in a template you should be in charge of defining that template or know how it is defined.

Hope this helps.

Who is online

Users browsing this forum: No registered users and 3 guests