0

I have a wpf TabControl which I added a ScrollViewer to. This is all wrapped into a style which is situated in a resource dictionary.

Now, on the window's xaml side, all I do is set .

I would like to access the control viewer element, as defined in the style as follows:

<Style x:Key="MyTabStyle" TargetType="{x:Type TabControl}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type TabControl}">
                 <ScrollViewer />
                        .......

How do I access the ScrollViewer which is so deeply nested in the hierarchy?

Alex
  • 21,273
  • 10
  • 61
  • 73
bluebit
  • 2,987
  • 7
  • 34
  • 42

1 Answers1

0

Give it a name (theScrollViewer for instance), and use the FindName method to access it :

ScrollViewer scrollViewer = theTabControl.Template.FindName("theScrollViewer") as ScrollViewer;
Thomas Levesque
  • 286,951
  • 70
  • 623
  • 758