WPF inside native application, hwndSource is sometimes empty (rendering) and other problems

Code Wanderer 396 Reputation points
2020-12-07T16:58:52.187+00:00

fro my plugin I use WPF for GUI. Everything works ok, but sometimes, when window (host) is opened, the hwnSource show blank space. When mouse is over some interactive element (button which have mouse over state and change a color) it redraw a rectangle area with only this element. It looks like, when hwndSource is created, it is drawed before it is added into external window.

Btw. I use custom application run, for animations and multithreading, therefore whole GUI have own thread.

I created workaround, where I use LayoutUpdate() when main view is loaded. Then i am sure that hwndSource allways draw a xaml.
But I have another problem, when window area is partialy outside a screen area and is bring back, the area outside screen is erased, become a blank and sometimes there are "stripe" artifacts.

I dont't know if this is host application problem, my or both? For example some another host application show my GUI without this problem, but new problem arise, when ComboBox is checked and items are shown, it hide window where is hwndSource displayed, but comboBox items stay displayed, this is annoying.
Maybe I have to add another flags for sourceParam.WindowStyle ?


My idea is listen to window changes (with AddHook for hwndSource) and then update WPF for example, when window is repositioned, etc.. to update a Layout. It is good idea?


Here is how I create a hwndSource
code mf_GetViewT(void** view) is called from host application.

    private void mf_GetView()
    {
        try
        {
            if (source != null)
            {
                source.Dispose();
            }

            sourceParam = new HwndSourceParameters("XXX");
            sourceParam.PositionX = 0;
            sourceParam.PositionY = 0;
            sourceParam.ParentWindow = ip;
            sourceParam.WindowStyle = WS_VISIBLE | WS_CHILD;

            source = new HwndSource(sourceParam);
            source.SizeToContent = SizeToContent.WidthAndHeight;
            source.RootVisual = this;
        }
        catch (Exception e)
        {
            MessageBox.Show( e.ToString());
        }

        mf_WaitSet();
    }

    unsafe public void mf_GetViewT(void** view)
    {
        ip = new IntPtr(*view);
        this.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal
            , new delegates.d_void(mf_GetView));
    }
Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,774 questions
0 comments No comments
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.