Shanadas
Shanadas

Reputation: 535

CEFGlue in plug-in enviornment not rendering

I have been referring the "CefGlue.Samples.WpfOsr" inside the CEFGlue samples available at https://bitbucket.org/xilium/xilium.cefglue/downloads and trying to integrate the same in a plug-in assembly. No matter what ever I do, the browser control doesn't get renderd in the view when run as a plug-in. However this works fine when run in standalone mode. Can someone advise how to go about?

Upvotes: 0

Views: 146

Answers (1)

Shanadas
Shanadas

Reputation: 535

So I found the root cause why the control was not showing up. Somewhere in the CEFGlue code base was following line, which makes it traverse the visual tree all the way up looking for type “Window” so as to get its parent window handle and render CEFBrowser control's UI.

Window parentWnd = FindParentOfType<Window>(this);

private static T FindParentOfType<T>(DependencyObject obj) where T : DependencyObject
        {
            DependencyObject parentObj = VisualTreeHelper.GetParent(obj);
            if (parentObj == null)
                return null;

            // Try to type cast the parent to the desired type.
            // If the cast succeeds, we've found the desired parent.
            T parent = parentObj as T;
            if (parent != null)
                return parent;

            // If we get here, the current parent wasn't of the right type, so keep looking recursively
            return FindParentOfType<T>(parentObj);
        }

May be because of the plug-in enviornment I have, this visual tree didn't have that kind of a parent Window, resulting a null handle. So the solution in my case was to find the main window handle of the parent process and give it to CEF. Hope it may help some one with similar situations.

Upvotes: 0

Related Questions