I am trying to understand how notification works for Attached Properties in WPF.
For example, consider the ScrollViewer.CanContentScrollProperty property.
Suppose we have the following ListBox
<ListBox x:Name="MainListBox"
Grid.Row="1"
ScrollViewer.CanContentScroll="False">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding CustomerID}"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
And in the Window code we will write the following code
private void Button_Click_1(object sender, RoutedEventArgs e)
{
MainListBox.SetValue(ScrollViewer.CanContentScrollProperty, true);
}
After executing Button_Click_1, the ListBox will automatically switch to CanContentScroll = true mode, but it is not clear how ScrollViewer receives information that the values of the connected property have been changed. It can be assumed that through the function FrameworkPropertyMetadata (PropertyChangedCallback propertyChangedCallback) , but the fact is that the property ScrollViewer.CanContentScrollProperty does not define a PropertyChanged function.
Here is the declaration code for this property.
public class ScrollViewer : ContentControl
...
public static readonly DependencyProperty CanContentScrollProperty = DependencyProperty.RegisterAttached(
nameof (CanContentScroll), typeof (bool), typeof (ScrollViewer),
(PropertyMetadata) new FrameworkPropertyMetadata(BooleanBoxes.FalseBox));
It can be seen that the function for the change is not registered.
How then does ScrollViewer know that a ScrollViewer.CanContentScrollProperty property has been changed?