/// <summary> /// Updates the display of the cue banner based on the control's content, focus and visibility. /// </summary> /// <param name="control">The control the cue banner is attached to.</param> private static void UpdateAdornerState(Control control) { if (control != null) { CueBannerAdorner adorner = GetCueBannerAdorner(control); if (adorner != null) { if (CueBannerService.HasContent(control) || !control.IsEnabled || control.Visibility != Visibility.Visible) { adorner.SetDisplayToHidden(); } else { if (control.IsFocused) { adorner.SetDisplayToDim(); } else { adorner.SetDisplayToNormal(); } } } } }
/// <summary> /// Gets the cue banner adorner which is applied to the control. /// </summary> /// <param name="control">The control the cue banner is attached to.</param> /// <returns>The cue banner adorner. If the adorner is not found then null is returned.</returns> private static CueBannerAdorner GetCueBannerAdorner(Control control) { CueBannerAdorner cueBannerAdorner = null; if (control != null) { AdornerLayer adornerLayer = AdornerLayer.GetAdornerLayer(control); if (adornerLayer != null) { Adorner[] adorners = adornerLayer.GetAdorners(control); if (adorners != null) { foreach (Adorner adorner in adorners) { if (adorner is CueBannerAdorner) { cueBannerAdorner = adorner as CueBannerAdorner; } } } } } return(cueBannerAdorner); }
/// <summary> /// Event handler that adds the cue banner to the control. /// </summary> /// <param name="sender">The object where the event handler is attached.</param> /// <param name="e">The event data.</param> private static void Control_Loaded(object sender, RoutedEventArgs e) { Control control = sender as Control; AdornerLayer adornerLayer = AdornerLayer.GetAdornerLayer(control); CueBannerAdorner cueBannerAdorner = new CueBannerAdorner(control, CueBannerService.GetCueBanner(control)); adornerLayer.Add(cueBannerAdorner); CueBannerService.UpdateAdornerState(control); }