Usage of triggers relying on a TargetElement - Herdo/AdaptiveTriggerLibrary GitHub Wiki

Certain triggers require a TargetElement in order to work properly. Those elements must be of type FrameworkElement.

The triggers relying on those elements attach to certain events in order to update themself, once the underlying element raises the event. When having a long running application with many loads and unloads of pages, you might run into a memory problem. The setters of the TargetElement properties attach - and detach! - the event handlers. If you don't set the TargetElement to null when a page unloads, the underlying FrameworkElement won't be removed from memory, as the trigger/event handler will still hold the reference to it.

Example:

private void OnUnloaded(object sender, RoutedEventArgs routedEventArgs)
{
    Unloaded -= OnUnloaded;

    // e.g., those types have a TargetElement property:
    InputTypeTrigger.TargetElement = null;
    ControlWidthTrigger.TargetElement = null;
    ControlHeightTrigger.TargetElement = null;
}