A cross-platform UI framework for .NET
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

94 lines
2.5 KiB

// -----------------------------------------------------------------------
// <copyright file="Application.cs" company="Steven Kirk">
// Copyright 2014 MIT Licence. See licence.md for more information.
// </copyright>
// -----------------------------------------------------------------------
namespace Perspex
{
using System;
using Perspex.Controls;
using Perspex.Input;
using Perspex.Styling;
using Perspex.Threading;
using Splat;
public class Application
{
private DataTemplates dataTemplates;
private Styler styler = new Styler();
public Application(Styles theme)
{
if (Current != null)
{
throw new InvalidOperationException("Cannot create more than one Application instance.");
}
Current = this;
this.Styles = theme;
this.FocusManager = new FocusManager();
this.InputManager = new InputManager();
this.RegisterServices();
}
public static Application Current
{
get;
private set;
}
public DataTemplates DataTemplates
{
get
{
if (this.dataTemplates == null)
{
this.dataTemplates = new DataTemplates();
}
return this.dataTemplates;
}
set
{
this.dataTemplates = value;
}
}
public IFocusManager FocusManager
{
get;
private set;
}
public InputManager InputManager
{
get;
private set;
}
public Styles Styles
{
get;
private set;
}
protected virtual void RegisterServices()
{
Locator.CurrentMutable.Register(() => this.DataTemplates, typeof(IGlobalDataTemplates));
Locator.CurrentMutable.Register(() => this.Styles, typeof(IGlobalStyle));
Locator.CurrentMutable.Register(() => this.FocusManager, typeof(IFocusManager));
Locator.CurrentMutable.Register(() => this.InputManager, typeof(IInputManager));
Locator.CurrentMutable.Register(() => this.styler, typeof(IStyler));
}
public void Run(ICloseable closable)
{
DispatcherFrame frame = new DispatcherFrame();
closable.Closed += (s, e) => frame.Continue = false;
Dispatcher.PushFrame(frame);
}
}
}