As per MSDN documentation of LayoutUpdated event -
When you handle LayoutUpdated, do not rely on the sender value. For LayoutUpdated, sender is always null, regardless of where the handler is attached. This is to prevent handlers from assigning any meaning to sender, such as implying that it was that specific element that raised the event out of the visual tree.
Instead you can hook to loaded event
-
if (e.NewValue != null && (bool)e.NewValue)
sp.Loaded += sp_Loaded;
else
sp.Loaded -= sp_Loaded;