private HeaderedToolTip CreateWrapperControl() { var tt = new HeaderedToolTip(); CreateBinding(ContentProperty, ContentControl.ContentProperty, tt); CreateBinding(ContentStringFormatProperty, ContentControl.ContentStringFormatProperty, tt); CreateBinding(TitleProperty, HeaderedContentControl.HeaderProperty, tt); CreateBinding(TitleStringFormatProperty, HeaderedContentControl.HeaderStringFormatProperty, tt); CreateBinding(CategoryProperty, HeaderedToolTip.CategoryProperty, tt); CreateBinding(MaxWidthProperty, FrameworkElement.MaxWidthProperty, tt); return(tt); }
private void InitControls() { popup = new Popup { PlacementRectangle = PopupPlacementRectangle, Placement = PopupMousePosition, HorizontalOffset = 5, VerticalOffset = 5, AllowsTransparency = true }; if (AssociatedObjectPlacementTarget) { popup.PlacementTarget = AssociatedObject; } popup.MouseEnter += OnPopupMouseEnter; popup.MouseLeave += OnPopupMouseLeave; if (IsMovable) { popup.MouseLeftButtonDown += (f3, g3) => { var element = f3 as FrameworkElement; _initialMousePosition = g3.GetPosition(null); element.CaptureMouse(); _isDragging = true; g3.Handled = true; }; popup.MouseMove += (f2, g2) => { if (_isDragging) { var currentPoint = g2.GetPosition(null); popup.HorizontalOffset += (currentPoint.X - _initialMousePosition.X); popup.VerticalOffset += (currentPoint.Y - _initialMousePosition.Y); } }; popup.MouseLeftButtonUp += (f, g) => { if (_isDragging) { var element = f as FrameworkElement; element.ReleaseMouseCapture(); _isDragging = false; g.Handled = true; } }; } var binding = new Binding { Path = new PropertyPath(FrameworkElement.DataContextProperty), Mode = BindingMode.OneWay, Source = AssociatedObject }; BindingOperations.SetBinding(popup, FrameworkElement.DataContextProperty, binding); toolTip = Content as HeaderedToolTip ?? CreateWrapperControl(); popup.Child = toolTip; toolTip.IsHitTestVisible = IsInteractive; toolTip.Tag = this; toolTip.ApplyTemplate(); VisualStateManager.GoToState(toolTip, "Closed", false); }