Pages

Saturday, September 15, 2012

SelfNote: SilverLight GetRoot


To get the current window, should use Window.GetWindow(currentElement) and then find Visual, not the Application.Current.RootVisual.

private static void SetRootVisual()
{
    if ((_rootVisual == null) && (Application.Current != null))
    {
        _rootVisual = Application.Current.RootVisual as FrameworkElement;
        if (_rootVisual != null)
        {
            _rootVisual.MouseMove += new MouseEventHandler(ToolTipService.OnRootMouseMove);
            _rootVisual.SizeChanged += new SizeChangedEventHandler(ToolTipService.OnRootVisualSizeChanged);
        }
    }
}

No comments: