public ApplicationSprite()
        {
            this.InvokeWhenStageIsReady(
                delegate
            {
                this.stage.align     = StageAlign.TOP_LEFT;
                this.stage.scaleMode = StageScaleMode.NO_SCALE;

                var fullscreen = new ScriptCoreLib.ActionScript.flash.ui.ContextMenuItem("Go fullscreen!");

                fullscreen.menuItemSelect +=
                    delegate
                {
                    this.stage.SetFullscreen(true);
                };

#if FcontextMenu
                this.contextMenu = new ScriptCoreLib.ActionScript.flash.ui.ContextMenu
                {
                    customItems = new[] { fullscreen }
                };
#endif


                var c = new ApplicationCanvas();
                c.AttachToContainer(this);


                this.stage.resize +=
                    e =>
                {
                    c.SizeTo(this.stage.stageWidth, this.stage.stageHeight);
                };

                c.SizeTo(this.stage.stageWidth, this.stage.stageHeight);
            }
                );
        }
        public static void Main(string[] args)
        {
            //System.Diagnostics.Debug.WriteLine(
            //    typeof(Tuple).AssemblyQualifiedName
            //);


            //System.Diagnostics.Debug.WriteLine(
            //    typeof(Tuple<,>).AssemblyQualifiedName
            //);

            //Debugger.Break();

#if DEBUG
            var Spawn = default(Action<Action<Window>>);
            var Session = new List<ApplicationCanvas>();

            Spawn = WindowCreated =>
                {
                    var c = new ApplicationCanvas();

                    Session.Add(c);

                    c.ConnectToSession(Session.Except(new[] { c }));

                    

                    var w = c.ToWindow();

                    w.Title += " | F2 - Spawn, F11 - Fullscreen";

                    w.Closing +=
                        delegate
                        {
                            Session.Remove(c);
                        };

                    w.KeyUp +=
                        (s, e) =>
                        {
                            if (e.Key == Key.F2)
                                Spawn(k => k.Show());
                        };

                    w.KeyDown +=
                        (s, e) =>
                        {

                            if (e.Key == Key.Escape || e.Key == Key.F11)
                                if (w.WindowState == WindowState.Maximized)
                                {
                                    w.WindowState = WindowState.Normal;
                                    return;
                                }

                            if (e.Key == Key.F11)
                                if (w.WindowState == WindowState.Normal)
                                {
                                    w.WindowStyle = WindowStyle.None;
                                    w.WindowState = WindowState.Maximized;
                                    return;
                                }
                        };

                    w.StateChanged +=
                        (s, e) =>
                        {
                            w.WindowStyle = w.WindowState == WindowState.Maximized ? WindowStyle.None : WindowStyle.SingleBorderWindow;
                        };


                    w.Loaded +=
                        delegate
                        {
                            w.SizeToContent = SizeToContent.Manual;
                            w.Focus();
                        };

                    w.SizeChanged +=
                        (s, e) =>
                        {
                            if (e.PreviousSize.Width == 0)
                                return;

                            // Content dictates its size. Yet when we resize the window we want the content to know it has more room.
                            // http://stackoverflow.com/questions/1081580/how-to-set-wpf-windows-startup-clientsize
                            var horizontalBorderHeight = SystemParameters.ResizeFrameHorizontalBorderHeight;
                            var verticalBorderWidth = SystemParameters.ResizeFrameVerticalBorderWidth;
                            var captionHeight = SystemParameters.CaptionHeight;

                            var Width = e.NewSize.Width;

                            var Height = e.NewSize.Height;


                            Width -= 2 * verticalBorderWidth;
                            Height -= 2 * horizontalBorderHeight;


                            if (w.WindowStyle != WindowStyle.None)
                            {
                                Height -= captionHeight;
                            }

                            c.SizeTo(Width, Height);

                        };

                    if (WindowCreated != null)
                        WindowCreated(w);
                };

            Spawn(w => w.ShowDialog());
#else

            RewriteToUltraApplication.AsProgram.Launch(typeof(Application));
#endif
        }
        public ApplicationSprite()
        {
            this.InvokeWhenStageIsReady(
                delegate
                {
                    this.stage.align = StageAlign.TOP_LEFT;
                    this.stage.scaleMode = StageScaleMode.NO_SCALE;

                    var fullscreen = new ScriptCoreLib.ActionScript.flash.ui.ContextMenuItem("Go fullscreen!");

                    fullscreen.menuItemSelect +=
                        delegate
                        {
                            this.stage.SetFullscreen(true);
                        };

#if FcontextMenu
                    this.contextMenu = new ScriptCoreLib.ActionScript.flash.ui.ContextMenu
                    {
                        customItems = new[] { fullscreen }
                    };
#endif


                    var c = new ApplicationCanvas();
                    c.AttachToContainer(this);


                    this.stage.resize +=
                        e =>
                        {

                            c.SizeTo(this.stage.stageWidth, this.stage.stageHeight);
                        };

                    c.SizeTo(this.stage.stageWidth, this.stage.stageHeight);
                }
            );
        }
        public static void Main(string[] args)
        {
            //System.Diagnostics.Debug.WriteLine(
            //    typeof(Tuple).AssemblyQualifiedName
            //);


            //System.Diagnostics.Debug.WriteLine(
            //    typeof(Tuple<,>).AssemblyQualifiedName
            //);

            //Debugger.Break();

#if DEBUG
            var Spawn   = default(Action <Action <Window> >);
            var Session = new List <ApplicationCanvas>();

            Spawn = WindowCreated =>
            {
                var c = new ApplicationCanvas();

                Session.Add(c);

                c.ConnectToSession(Session.Except(new[] { c }));



                var w = c.ToWindow();

                w.Title += " | F2 - Spawn, F11 - Fullscreen";

                w.Closing +=
                    delegate
                {
                    Session.Remove(c);
                };

                w.KeyUp +=
                    (s, e) =>
                {
                    if (e.Key == Key.F2)
                    {
                        Spawn(k => k.Show());
                    }
                };

                w.KeyDown +=
                    (s, e) =>
                {
                    if (e.Key == Key.Escape || e.Key == Key.F11)
                    {
                        if (w.WindowState == WindowState.Maximized)
                        {
                            w.WindowState = WindowState.Normal;
                            return;
                        }
                    }

                    if (e.Key == Key.F11)
                    {
                        if (w.WindowState == WindowState.Normal)
                        {
                            w.WindowStyle = WindowStyle.None;
                            w.WindowState = WindowState.Maximized;
                            return;
                        }
                    }
                };

                w.StateChanged +=
                    (s, e) =>
                {
                    w.WindowStyle = w.WindowState == WindowState.Maximized ? WindowStyle.None : WindowStyle.SingleBorderWindow;
                };


                w.Loaded +=
                    delegate
                {
                    w.SizeToContent = SizeToContent.Manual;
                    w.Focus();
                };

                w.SizeChanged +=
                    (s, e) =>
                {
                    if (e.PreviousSize.Width == 0)
                    {
                        return;
                    }

                    // Content dictates its size. Yet when we resize the window we want the content to know it has more room.
                    // http://stackoverflow.com/questions/1081580/how-to-set-wpf-windows-startup-clientsize
                    var horizontalBorderHeight = SystemParameters.ResizeFrameHorizontalBorderHeight;
                    var verticalBorderWidth    = SystemParameters.ResizeFrameVerticalBorderWidth;
                    var captionHeight          = SystemParameters.CaptionHeight;

                    var Width = e.NewSize.Width;

                    var Height = e.NewSize.Height;


                    Width  -= 2 * verticalBorderWidth;
                    Height -= 2 * horizontalBorderHeight;


                    if (w.WindowStyle != WindowStyle.None)
                    {
                        Height -= captionHeight;
                    }

                    c.SizeTo(Width, Height);
                };

                if (WindowCreated != null)
                {
                    WindowCreated(w);
                }
            };

            Spawn(w => w.ShowDialog());
#else
            RewriteToUltraApplication.AsProgram.Launch(typeof(Application));
#endif
        }