A question about Microsoft.SPOT.Touch

My curious mind.
To be, or not to be … Whether 'tis nobler in the mind to suffer wondering why or just ask the question.

Using the original FEZ Spider - Firmware 4.3.7.10 - VS2013

I wanted to make a small test application to test a Touch problem I was having. It really does not matter for this question but on occasion I am getting a touch down event far form where the stylus was pressed.
(Probably my old worn out nerves)

My question is why does the T35 display go to all white as soon as the program starts.
Screen goes to all white on p.Run();

Code used:


namespace CalibTest
{
    public partial class Program
    {
        private Bitmap lcd;

        //Created from a previous calibration for my old T35
        private static short[] sx = { 160, 32, 32, 288, 288 };
        private static short[] sy = { 120, 24, 216, 216, 24 };
        private static short[] cx = { 463, 165, 158, 774, 789 };
        private static short[] cy = { 457, 213, 744, 713, 205 };

        Font fontSmall;

        // This method is run when the mainboard is powered up or reset.   
        void ProgramStarted()
        {
            fontSmall = Resources.GetFont(Resources.FontResources.small);

            display.SimpleGraphics.BackgroundColor = Color.Black;

            //Used to display a message after program starts
            GT.Timer timer = new GT.Timer(1000); //1000ms
            timer.Tick += timer_Tick;

            button4.ButtonPressed += button4_ButtonPressed;

            lcd = new Bitmap(SystemMetrics.ScreenWidth, SystemMetrics.ScreenHeight);
            lcd.Clear();

            Touch.Initialize(Application.Current);
            Touch.ActiveTouchPanel.SetCalibration(5, sx, sy, cx, cy);

            display.WPFWindow.TouchDown += this.MainWindow_TouchDown;
            display.WPFWindow.TouchUp += this.MainWindow_TouchUp;
            display.WPFWindow.TouchMove += this.MainWindow_TouchMove;

            //This text would be seen on the display if I set a breakpoint at the end of ProgramStarted()
            //lcd.DrawTextInRect("Press button 4 to begin", 20, 20, SystemMetrics.ScreenWidth, SystemMetrics.ScreenHeight, 1, Colors.Yellow, fontSmall);
            //lcd.Flush();

            //The display would go all white. Suppressed using Visibility.Hidden below.
            //Occurs on - Start Dispatcher p.Run(); - Program.generated.cs

            
            bool showproblem; // Your choice
            showproblem = true;
            //showproblem = false;

            //Show the problem
            if(showproblem)
            {
                alloyTouch = true;
                //App runs OK but you need to "Press button 4 to begin"
                //If the Touch events were not suppressed by bool alloyTouch
                //touching the display would show the message.
            }

            if (!showproblem)
            {
                //Suppress a very annoying white screen flash on program start
                display.WPFWindow.Visibility = Visibility.Hidden;
                //Display my message on timer tick
                timer.Start();
            }
            //

        }
        //

        void timer_Tick(GT.Timer timer)
        {
            Debug.Print("TICK");
            timer.Stop();
            lcd.DrawTextInRect("Press button 4 to begin", 20, 20, SystemMetrics.ScreenWidth, SystemMetrics.ScreenHeight, 1, Colors.Yellow, fontSmall);
            lcd.Flush();
        }
        //

        bool isfirst = true;
        bool alloyTouch = false;
        void button4_ButtonPressed(Button sender, Button.ButtonState state)
        {
            if (isfirst)
            {
                isfirst = false;
                alloyTouch = true;
                drawRectangle();
                lcd.DrawText("Touch me! Press button again to clear display", fontSmall, MSPM.Colors.Yellow, 10, 10);
                lcd.Flush();
            }
            else
            {
                lcd.Dispose();
                lcd = new Bitmap(SystemMetrics.ScreenWidth, SystemMetrics.ScreenHeight);
                lcd.Clear();
                drawRectangle();
                
                lcd.DrawText("Touch me!", fontSmall, MSPM.Colors.Yellow, 10, 10);
                lcd.Flush();
            }
            //
        }
        //

        private void MainWindow_TouchDown(object sender, TouchEventArgs e)
        {
            if (!alloyTouch)
            {
                return;
            }
            //

            Debug.Print("Touch down at (" + e.Touches[0].X.ToString() + ", " + e.Touches[0].Y.ToString() + ")");

            lcd.DrawEllipse(Colors.Red, e.Touches[0].X, e.Touches[0].Y, 5, 5);
            lcd.Flush();
        }
        //
        private void MainWindow_TouchUp(object sender, TouchEventArgs e)
        {
            if (!alloyTouch)
            {
                return;
            }
            //

            Debug.Print("Touch up at (" + e.Touches[0].X.ToString() + ", " + e.Touches[0].Y.ToString() + ")");
            
            lcd.DrawEllipse(Colors.Yellow, e.Touches[0].X, e.Touches[0].Y, 4, 4);
            lcd.Flush();
        }
        //

        private void MainWindow_TouchMove(object sender, TouchEventArgs e)
        {
            if (!alloyTouch)
            {
                return;
            }
            //

            Debug.Print("Touch move at (" + e.Touches[0].X.ToString() + ", " + e.Touches[0].Y.ToString() + ")");

            lcd.DrawEllipse(Colors.Blue, e.Touches[0].X, e.Touches[0].Y, 3, 3);
            lcd.Flush();
        }
        //

        void drawRectangle()
        {
            lcd.DrawRectangle(Colors.White, // outline color
                     1, //
                     0, // x
                     0, // y
                     SystemMetrics.ScreenWidth, // width
                     SystemMetrics.ScreenHeight,    // height
                     0, // x corner radius
                     0, // y corner radius
                     Colors.Black,  // start gradient color
                     0, // start gradient x
                     0, // start gradient y
                     Colors.Black,  // end gradient color
                     SystemMetrics.ScreenWidth, // end gradient x
                     SystemMetrics.ScreenHeight,    // end gradient y
                     0xFF); // opacity
        }
        //
    }
}
//

Thanks in advance

@ willgeorge - I believe it is because you are mixing SimpleGraphics and WPF. WPF takes over the entire display. It goes white because that is the default background color, there are no controls added, and it starts to run right away. The last drawn entity wins usually.

@ John -

Thank you for your reply.