Black background before loading a wpf controll when using ElementHost

前端 未结 3 1391
迷失自我
迷失自我 2020-12-10 23:50

I\'m using WPF in WinForms with ElementHost. When the form loads, there is a flash of black background where the ElementHost is about to load. This looks kind of bad. Any su

3条回答
  •  感动是毒
    2020-12-11 00:07

    you need first show control with empty bounds first time to avoid black flickering

    if (!_control.Created && _control.BackColor != Color.Transparent)
    {
        _control.Bounds = Rectangle.Empty;
        _control.Show();
    }
    
    // set control bounds and show it
    Rectangle bounds = GetBounds(context, rect);
    if (_control.Bounds != bounds)
        _control.Bounds = bounds;
    if (!_control.Visible)
        _control.Show();
    

提交回复
热议问题