I'm learning to develop custom controls for UWP and I have to develop a control that contains a ScrollViewer. The generic.xaml looks like this:
<Style TargetType="local:TemplatedScroller" >
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="local:TemplatedScroller">
<ScrollViewer x:Name="NumberScroller"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}">
</ScrollViewer>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
The corresponding cs class is pretty simple right now.
public sealed class TemplatedScroller : Control
{
public TemplatedScroller()
{
this.DefaultStyleKey = typeof(TemplatedScroller);
}
private ScrollViewer numberScroller;
protected override void OnApplyTemplate()
{
base.OnApplyTemplate();
numberScroller = GetTemplateChild("NumberScroller") as ScrollViewer;
}
}
In my control I have to know when the user will scroll the content so I thought that I can register a property changed callback for scroller's VerticalOffset property using RegisterPropertyChangedCallback. I can register the callback in OnApplyTemplate method.
My question is where should I call the corresponding UnregisterPropertyChangedCallback? I could not find any Unload method (or similar) to override. Or is my approach wrong and this is not the way to do things in UWP?