/// <summary> /// Handle the Loaded and LostFocus event on the control /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">A <see cref="RoutedEventArgs"/> that contains the event data.</param> private static void control_Loaded(object sender, RoutedEventArgs e) { Control control = (Control)sender; if (PlaceholderService.shouldShowWatermark(control)) { PlaceholderService.showWatermark(control); } }
/// <summary> /// Show the watermark on the specified control /// </summary> /// <param name="control">Control to show the watermark on</param> private static void showWatermark(Control control) { AdornerLayer layer = AdornerLayer.GetAdornerLayer(control); // layer could be null if control is no longer in the visual tree if (layer != null && control != null) { layer.Add(new PlaceholderAdorner(control, PlaceholderService.GetPlaceholder(control))); } }
/// <summary> /// Handle the GotFocus event on the control /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">A <see cref="RoutedEventArgs"/> that contains the event data.</param> private static void control_GotKeyboardFocus(object sender, RoutedEventArgs e) { Control c = (Control)sender; if (PlaceholderService.shouldShowWatermark(c)) { PlaceholderService.showWatermark(c); } else { PlaceholderService.removeWatermark(c); } }
/// <summary> /// Event handler for the items changed event /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">A <see cref="ItemsChangedEventArgs"/> that contains the event data.</param> private static void itemsChanged(object sender, ItemsChangedEventArgs e) { ItemsControl control; if (itemsControls.TryGetValue(sender, out control)) { if (PlaceholderService.shouldShowWatermark(control)) { PlaceholderService.showWatermark(control); } else { PlaceholderService.removeWatermark(control); } } }
/// <summary> /// Event handler for the items source changed event /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">A <see cref="EventArgs"/> that contains the event data.</param> private static void itemsSourceChanged(object sender, EventArgs e) { ItemsControl c = (ItemsControl)sender; if (c.ItemsSource != null) { if (PlaceholderService.shouldShowWatermark(c)) { PlaceholderService.showWatermark(c); } else { PlaceholderService.removeWatermark(c); } } else { PlaceholderService.showWatermark(c); } }