1
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
2
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
6
using ICSharpCode.WpfDesign.Designer.Controls;
8
namespace ICSharpCode.WpfDesign.Designer.Services
10
sealed class DefaultErrorService : IErrorService
12
sealed class AttachedErrorBalloon : ErrorBalloon
14
FrameworkElement attachTo;
16
public AttachedErrorBalloon(FrameworkElement attachTo, UIElement errorElement)
18
this.attachTo = attachTo;
19
this.Content = errorElement;
22
internal void AttachEvents()
24
attachTo.Unloaded += OnCloseEvent;
25
attachTo.PreviewKeyDown += OnCloseEvent;
26
attachTo.PreviewMouseDown += OnCloseEvent;
27
attachTo.LostFocus += OnCloseEvent;
30
void OnCloseEvent(object sender, EventArgs e)
35
protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
37
attachTo.Unloaded -= OnCloseEvent;
38
attachTo.PreviewKeyDown -= OnCloseEvent;
39
attachTo.PreviewMouseDown -= OnCloseEvent;
40
attachTo.LostFocus -= OnCloseEvent;
44
protected override void OnMouseDown(System.Windows.Input.MouseButtonEventArgs e)
51
ServiceContainer services;
53
public DefaultErrorService(DesignContext context)
55
this.services = context.Services;
58
public void ShowErrorTooltip(FrameworkElement attachTo, UIElement errorElement)
61
throw new ArgumentNullException("attachTo");
62
if (errorElement == null)
63
throw new ArgumentNullException("errorElement");
65
AttachedErrorBalloon b = new AttachedErrorBalloon(attachTo, errorElement);
66
Point pos = attachTo.PointToScreen(new Point(0, attachTo.ActualHeight));
70
ITopLevelWindowService windowService = services.GetService<ITopLevelWindowService>();
71
ITopLevelWindow ownerWindow = (windowService != null) ? windowService.GetTopLevelWindow(attachTo) : null;
72
if (ownerWindow != null) {
73
ownerWindow.SetOwner(b);
77
if (ownerWindow != null) {
78
ownerWindow.Activate();