ui/wpf/UIcore/Window.cs

Tue, 27 Jan 2015 09:59:32 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Tue, 27 Jan 2015 09:59:32 +0100
changeset 82
0cdb8089a29f
parent 81
5eb765a7a793
child 83
a38aec91bd66
permissions
-rw-r--r--

added event handler for 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 IntPtr Object;
        
        public MainWindow(String title, IntPtr uiobj)
        {
            Title = title;
            Object = uiobj;
            Width = 300;
            Height = 300;

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

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

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

        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