/// <summary>
        /// Loads the companion ad into the UI.
        /// </summary>
        /// <param name="source">Source information for the companion ad</param>
        /// <param name="unloadAction">The action to perform when it is time to unload the companion.</param>
        /// <returns>An action to undo the loaded companion if successful. Null if not.</returns>
        public virtual bool TryLoadCompanion(ICompanionSource source, out Action unloadAction)
        {
            if ((source.Type == CompanionType.Static))
            {
                FrameworkElement container = GetCompanionContainer(source);
                if (container != null)
                {
                    var companionHost = new CompanionHost();
                    if (CompanionHostStyle != null)
                    {
                        companionHost.Style = CompanionHostStyle;
                    }
                    var companionElement = new Image()
                    {
                        Source  = new BitmapImage(new Uri(source.Content)),
                        Stretch = Stretch.Fill,
                        Tag     = source
                    };
                    companionHost.Content     = companionElement;
                    companionHost.NavigateUri = source.ClickThrough;
                    companionHost.Tag         = source;

                    if (!string.IsNullOrEmpty(source.AltText))
                    {
                        ToolTipService.SetToolTip(companionHost, new ToolTip()
                        {
                            Content = source.AltText
                        });
                    }

                    Action unwireViewTrackingAction = null;
                    if (source.ViewTracking != null && source.ViewTracking.Any())
                    {
                        companionElement.ImageOpened += companionElement_ImageOpened;
                        unwireViewTrackingAction      = () => companionElement.ImageOpened -= companionElement_ImageOpened;
                    }

                    Action unwireClickTrackingAction = null;
                    if (source.ClickTracking != null && source.ClickTracking.Any())
                    {
                        companionHost.Click      += companionHost_Click;
                        unwireClickTrackingAction = () => companionHost.Click -= companionHost_Click;
                    }

                    if (container is Border)
                    {
                        ((Border)container).Child = companionHost;
                        unloadAction = () =>
                        {
                            if (unwireClickTrackingAction != null)
                            {
                                unwireClickTrackingAction();
                            }
                            if (unwireViewTrackingAction != null)
                            {
                                unwireViewTrackingAction();
                            }
                            ((Border)container).Child = null;
                        };
                        return(true);
                    }
                    else if (container is Panel)
                    {
                        ((Panel)container).Children.Add(companionHost);
                        unloadAction = () =>
                        {
                            if (unwireClickTrackingAction != null)
                            {
                                unwireClickTrackingAction();
                            }
                            if (unwireViewTrackingAction != null)
                            {
                                unwireViewTrackingAction();
                            }
                            ((Panel)container).Children.Remove(companionHost);
                        };
                        return(true);
                    }
                    else if (container is ContentControl)
                    {
                        ((ContentControl)container).Content = companionHost;
                        unloadAction = () =>
                        {
                            if (unwireClickTrackingAction != null)
                            {
                                unwireClickTrackingAction();
                            }
                            if (unwireViewTrackingAction != null)
                            {
                                unwireViewTrackingAction();
                            }
                            ((ContentControl)container).Content = null;
                        };
                        return(true);
                    }
                    if (unwireClickTrackingAction != null)
                    {
                        unwireClickTrackingAction();
                    }
                    if (unwireViewTrackingAction != null)
                    {
                        unwireViewTrackingAction();
                    }
                }
            }
            unloadAction = null;
            return(false);
        }
        /// <summary>
        /// Loads the companion ad into the UI.
        /// </summary>
        /// <param name="source">Source information for the companion ad</param>
        /// <param name="unloadAction">The action to perform when it is time to unload the companion.</param>
        /// <returns>An action to undo the loaded companion if successful. Null if not.</returns>
        public virtual bool TryLoadCompanion(ICompanionSource source, out Action unloadAction)
        {
            if ((source.Type == CompanionType.Static))
            {
                FrameworkElement container = GetCompanionContainer(source);
                if (container != null)
                {
                    var companionHost = new CompanionHost();
                    if (CompanionHostStyle != null) companionHost.Style = CompanionHostStyle;
                    var companionElement = new Image()
                    {
                        Source = new BitmapImage(new Uri(source.Content)),
                        Stretch = Stretch.Fill,
                        Tag = source
                    };
                    companionHost.Content = companionElement;
                    companionHost.NavigateUri = source.ClickThrough;
                    companionHost.Tag = source;

                    if (!string.IsNullOrEmpty(source.AltText))
                    {
                        ToolTipService.SetToolTip(companionHost, new ToolTip() { Content = source.AltText });
                    }

                    Action unwireViewTrackingAction = null;
                    if (source.ViewTracking != null && source.ViewTracking.Any())
                    {
                        companionElement.ImageOpened += companionElement_ImageOpened;
                        unwireViewTrackingAction = () => companionElement.ImageOpened -= companionElement_ImageOpened;
                    }

                    Action unwireClickTrackingAction = null;
                    if (source.ClickTracking != null && source.ClickTracking.Any())
                    {
                        companionHost.Click += companionHost_Click;
                        unwireClickTrackingAction = () => companionHost.Click -= companionHost_Click;
                    }

                    if (container is Border)
                    {
                        ((Border)container).Child = companionHost;
                        unloadAction = () =>
                        {
                            if (unwireClickTrackingAction != null) unwireClickTrackingAction();
                            if (unwireViewTrackingAction != null) unwireViewTrackingAction();
                            ((Border)container).Child = null;
                        };
                        return true;
                    }
                    else if (container is Panel)
                    {
                        ((Panel)container).Children.Add(companionHost);
                        unloadAction = () =>
                        {
                            if (unwireClickTrackingAction != null) unwireClickTrackingAction();
                            if (unwireViewTrackingAction != null) unwireViewTrackingAction();
                            ((Panel)container).Children.Remove(companionHost);
                        };
                        return true;
                    }
                    else if (container is ContentControl)
                    {
                        ((ContentControl)container).Content = companionHost;
                        unloadAction = () =>
                        {
                            if (unwireClickTrackingAction != null) unwireClickTrackingAction();
                            if (unwireViewTrackingAction != null) unwireViewTrackingAction();
                            ((ContentControl)container).Content = null;
                        };
                        return true;
                    }
                    if (unwireClickTrackingAction != null) unwireClickTrackingAction();
                    if (unwireViewTrackingAction != null) unwireViewTrackingAction();
                }
            }
            unloadAction = null;
            return false;
        }