ui/wpf/UIcore/Window.cs

Sun, 25 Jan 2015 15:01:04 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 25 Jan 2015 15:01:04 +0100
changeset 81
5eb765a7a793
parent 78
135920fe441b
child 82
0cdb8089a29f
permissions
-rw-r--r--

added menus (WPF)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;

namespace UI
{
    public class MainWindow : Window
    { 
        public MainWindow(String title)
        {
            Title = title;
            Width = 300;
            Height = 300;

            // menu
            Application app = Application.GetInstance();
            if (!app.AppMenu.IsEmpty())
            {
                System.Windows.Controls.Menu menu = app.AppMenu.CreateMenu();
                this.AddChild(menu);
            }

            GC.KeepAlive(this); // TODO: remove KeepAlive and add the Window to the application
            Closed += CloseEvent;
        }

        public static MainWindow CreateMainWindow(String title)
        {
            return Application.GetInstance().Exec<MainWindow>(() => new MainWindow(title));
        }

        public void ShowWindow()
        {
            Application.GetInstance().Exec(() => this.Show());
            Application.GetInstance().AddWindow(this);
        }

        public void CloseEvent(object sender, System.EventArgs e)
        {
            Application.GetInstance().RemoveWindow(this);
        }
    }
}

mercurial