Rendering issue with WPF controls inside ElementHost

后端 未结 3 1115
时光说笑
时光说笑 2021-02-04 07:09

I am having a WinForms control, inside that I have a TableLayoutPanel which holds multiple ElementHosts and each ElementHost contains a WP

相关标签:
3条回答
  • 2021-02-04 07:53
    this.Loaded += delegate
    {
        var source = PresentationSource.FromVisual(this);
        var hwndTarget = source.CompositionTarget as HwndTarget;
    
        if (hwndTarget != null)
        {
            hwndTarget.RenderMode = RenderMode.SoftwareOnly;
        }
    };
    

    Try using that in the wpf control you are hosting. This is a known rendering issue of the the wpf controls that are hosted in win forms. Changing the rendering mode to software only will solve the problem.

    0 讨论(0)
  • 2021-02-04 07:55

    I had a similar problem and solved forcing a refresh of the ElmenetHost in the scroll event of the TableLayoutPanel

    0 讨论(0)
  • 2021-02-04 08:04

    Ok, this is gonna sound like total B.S. but it worked for me: in the Load event of your form, resize the form.

    public class MyForm : Form
    {
       public MyForm()
       {
          Load += (o, e) => { Width -=1; Width +=1; };
       }
    }
    

    After the form has been resized, I could not force a display issue.

    0 讨论(0)
提交回复
热议问题