public IWindow CreateWindow(WindowCreationSettings settings) { return(Application.Current.Dispatcher.Invoke(() => { SmartEarthWindow window = Container.Resolve <SmartEarthWindow>(); window.DataContext = settings.DataContext; if (settings.Style != null) { window.Style = settings.Style; } window.Topmost = settings.Topmost; window.WindowStartupLocation = settings.StartupLocation; window.SizeToContent = settings.SizeToContent; if (!string.IsNullOrWhiteSpace(settings.Title)) { window.Title = settings.Title; } if (settings.DataContext is IShellAware) { ((IShellAware)settings.DataContext).Load(window); } if (settings.IsModal) { window.ShowDialog(); } else { window.Show(); } Windows.Add(window); return window; })); }
protected DesktopGameContext(string title, WindowCreationSettings settings) : this(new Window(title, settings)) { }
/// <summary> /// /// </summary> /// <typeparam name="T">Usercontrol type of the window</typeparam> /// <param name="settings"></param> /// <returns></returns> public async Task <IWindow> CreateWindow <T>(WindowCreationSettings settings) where T : class { return(await Application.Current.Dispatcher.InvokeAsync(() => { SmartEarthWindow window = Container.Resolve <SmartEarthWindow>(); object content = Container.Resolve <T>(); window.Content = content; if (settings.DataContext != null) { window.DataContext = settings.DataContext; } if (settings.Style != null) { window.Style = settings.Style; } window.Topmost = settings.Topmost; window.WindowStartupLocation = settings.StartupLocation; settings.SizeToContent = settings.SizeToContent; if (!string.IsNullOrWhiteSpace(settings.Title)) { window.Title = settings.Title; } if (settings.DataContext is IShellAware) { ((IShellAware)settings.DataContext).Load(window); } else if (content is FrameworkElement && ((FrameworkElement)content).DataContext is IShellAware) { ((IShellAware)((FrameworkElement)content).DataContext).Load(window); } RoutedEventHandler loaded = null; window.Loaded += loaded = (s, e) => { window.Loaded -= loaded; if (!settings.RestrictResizing) { return; } Rect rect = new Rect(window.Left, window.Top, window.ActualWidth, window.ActualHeight); window.SizeToContent = SizeToContent.Manual; window.Left = rect.Left; window.Top = rect.Top; window.Width = rect.Width; window.Height = rect.Height; }; if (settings.IsModal) { window.ShowDialog(); } else { window.Show(); } Windows.Add(window); return window; })); }