/// <summary> /// Gets the fist control in a visual tree. /// </summary> /// <param name="element">The current element.</param> /// <returns>The first control in the tree.</returns> private static Control GetFirstControl(UIElement element) { Control control = element as Control; if (control != null) { return control; } Panel panel = element as Panel; if (panel != null) { foreach (UIElement child in panel.Children) { Control childControl = LabeledContentControl.GetFirstControl(child); if (childControl != null) { return childControl; } } } ContentPresenter contentPresenter = element as ContentPresenter; if (contentPresenter != null) { UIElement contentElement = contentPresenter.Content as UIElement; if (contentElement != null) { return LabeledContentControl.GetFirstControl(contentElement); } } return null; }
/// <summary> /// Gives focus to the first control in the tree. /// </summary> /// <param name="sender">The label area element.</param> /// <param name="e">Mouse Button Event Args.</param> private void LabelAreaElement_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { UIElement content = this.Content as UIElement; if (content != null) { Control control = LabeledContentControl.GetFirstControl(content); if (control != null) { FocusHelper.FocusControl(control); } } }
/// <summary> /// Updates the labels. /// </summary> /// <param name="startLabel">The start labeledcontentcontrol.</param> /// <param name="endLabel">The end labeledcontentcontrol.</param> /// <param name="newLabel">New label text for the start labeledcontentcontrol.</param> private static void UpdateLabels(LabeledContentControl startLabel, LabeledContentControl endLabel, string newLabel) { bool changeActualDateLabel = true; if (endLabel.Visibility == Visibility.Visible) { DateTime endDate = DateTime.Parse(endLabel.Content.ToString(), CultureInfo.CurrentCulture); DateTime startDate = DateTime.Parse(startLabel.Content.ToString(), CultureInfo.CurrentCulture); if (!endDate.Equals(startDate)) { changeActualDateLabel = false; } } if (changeActualDateLabel && startLabel.Visibility == Visibility.Visible) { startLabel.Label = newLabel; } }