-1

In my application, on menu click we are launching a window. While loading, window will be black for few seconds and then controls will appears. I have attached the image here for reference. Please help me .enter image description here .

mm8
  • 163,881
  • 10
  • 57
  • 88
Naveenkumar R
  • 89
  • 2
  • 15

2 Answers2

0

Do you import and use WindowChrome class (System.Windows.Shell) in your project? when i import this class to my project this problem happened.

mohsen mousavi
  • 262
  • 2
  • 7
0

You should read this:

How to fix the WPF form resize - controls lagging behind and black background?

You can change the colour of the black bit that shows by calling the SetClassLong method as suggested by @@ghord:

public static class WindowExtensions
{
    private const int GCL_HBRBACKGROUND = -10;
    private const int COLOR_WINDOW = 5;

    public static void SetClassLong(this Window window)
    {
        //change the background colour of the window to "hide" possible black rendering artifacts
        IntPtr handle = new WindowInteropHelper(window).EnsureHandle();
        if (handle != IntPtr.Zero)
            SetClassLong(handle, GCL_HBRBACKGROUND, SafeNativeMethods.GetSysColorBrush(COLOR_WINDOW));
    }

    private static IntPtr SetClassLong(IntPtr hWnd, int nIndex, IntPtr dwNewLong)
    {
        if (IntPtr.Size > 4)
            return SafeNativeMethods.SetClassLongPtr64(hWnd, nIndex, dwNewLong);
        else
            return new IntPtr(SafeNativeMethods.SetClassLongPtr32(hWnd, nIndex, unchecked((uint)dwNewLong.ToInt32())));
    }
}

public partial class MainWindow : Window, IViewFor<MainWindowViewModel>
{
    public MainWindow()
    {
        InitializeComponent();
    }

    protected override void OnSourceInitialized(EventArgs e)
    {
        base.OnSourceInitialized(e);
        //change the background colour of the window to "hide" possible black rendering artifacts
        this.SetClassLong();
    }
}
Community
  • 1
  • 1
mm8
  • 163,881
  • 10
  • 57
  • 88
  • Can you suggest any other solution other than setting background brush.? Because i tried with all suggested solutions above but did't work for me... – Naveenkumar R Jan 05 '17 at 03:47