Пример #1
0
        public static Window CreateWindow()
        {
            IntPtr hInstance           = Process.GetCurrentProcess().Handle;
            WindowConfiguration config = new WindowConfiguration();
            Window window;

            config.ClassName = Engine.ScriptingInterface.GetCvarValue <string>("w_className");
            config.Title     = Engine.ScriptingInterface.GetCvarValue <string>("w_title");
            config.X         = Engine.ScriptingInterface.GetCvarValue <int>("w_x");
            config.Y         = Engine.ScriptingInterface.GetCvarValue <int>("w_y");
            config.Width     = Engine.ScriptingInterface.GetCvarValue <int>("w_width");
            config.Height    = Engine.ScriptingInterface.GetCvarValue <int>("w_height");
            config.Mode      = Engine.ScriptingInterface.GetCvarValue <bool>("w_noBorder") ? WindowMode.NoBorder : WindowMode.Windowed;

            try
            {
                window = Window.CreateWindow(hInstance, config);
                window.Create();
            }
            catch (WindowException e)
            {
                throw new InitializeException("Failed to create window: {0}", e.Message);
            }

            return(window);
        }
Пример #2
0
 public void Setup(WindowConfiguration config)
 {
     this.WindowConfiguration = config;
     this.WindowTitle         = config.Title;
     this.ShowFPS             = config.ShowFPS;
     Player.Setup(config.Player);
 }
Пример #3
0
 protected override async void OnStartup(StartupEventArgs e)
 {
     var assembly     = typeof(App).Assembly;
     var windowConfig = WindowConfiguration.CreateWithDefaultIcon(assembly, "Test UI");
     var appConfig    = new WpfAppConfiguration(assembly, windowConfig);
     await AppStartService.StartAppAsync(appConfig);
 }
Пример #4
0
        private static void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            if (e.Cancel)
            {
                return;
            }

            var window    = sender as Window;
            var view      = window.Content as FrameworkElement;
            var viewModel = view.DataContext as IViewModel;

            if (WindowConfiguration.GetIsWindowPersistent(view))
            {
                PersistentWindowInformation.Save(window, viewModel.GetType());
            }

            if (viewModel is ICloseAwareViewModel closeAware)
            {
                e.Cancel = true;

                Factory.Create <IDispatcher>().RunAsync(async() =>
                {
                    if (await closeAware.CanClose())
                    {
                        window.Closing -= Window_Closing;
                        window.Closing += (s, args) => e.Cancel |= !Close(window);
                        window.Close();
                    }
                });
            }
            else
            {
                e.Cancel |= !Close(window);
            }
        }
Пример #5
0
        public CocoaWindow(WindowConfiguration config, WebviewBridge bridge)
        {
            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }
            if (bridge == null)
            {
                throw new ArgumentNullException(nameof(bridge));
            }

            Handle = AppKit.Call("NSWindow", "alloc");

            canResizeField = config.CanResize;
            var style = GetWantedStyleMask();

            ObjC.SendMessage(
                Handle,
                ObjC.RegisterName("initWithContentRect:styleMask:backing:defer:"),
                new CGRect(0, 0, config.Size.Width, config.Size.Height),
                new UIntPtr((uint)style),
                new UIntPtr(2),
                false);

            webview = new CocoaWebview(bridge);
            ObjC.Call(Handle, "setContentView:", webview.Handle);

            webview.TitleChanged += Webview_TitleChanged;

            windowDelegate = WindowDelegateDefinition.CreateInstance(this);
            ObjC.Call(Handle, "setDelegate:", windowDelegate.Handle);
        }
Пример #6
0
        private void LightWindow_SourceInitialized(object sender, EventArgs e)
        {
            this.hwnd       = this.GetWindowHandle();
            this.hwndSource = HwndSource.FromHwnd(this.hwnd);

            this.hwndSource.AddHook(this.WindowProc);
            this.border = this.Template.FindName("border", this) as Border;
            this.title  = this.Template.FindName("title", this) as TextBlock;
            this.icon   = this.Template.FindName("icon", this) as Image;

            this.minimizeButton = this.Template.FindName("MinimizeButton", this) as Button;
            this.maximizeButton = this.Template.FindName("MaximizeButton", this) as Button;
            this.restoreButton  = this.Template.FindName("RestoreButton", this) as Button;
            this.closeButton    = this.Template.FindName("CloseButton", this) as Button;

            this.SetWindowStateDependentEffects();

            if (this.icon != null)
            {
                this.icon.Effect = new GrayscaleEffect {
                    DesaturationFactor = 1.0
                }
            }
            ;

            if (WindowConfiguration.GetWindowStyle(this) == WindowStyle.None)
            {
                this.icon.IsNotNull(x => x.Visibility  = Visibility.Collapsed);
                this.title.IsNotNull(x => x.Visibility = Visibility.Collapsed);
            }

            //Win32Api.AddShadow(this, hwnd);
        }
Пример #7
0
 static ProgramOptions()
 {
     document            = new Document();
     language            = AppLanguage.English;
     vocabulary          = new Vocabulary();
     windowConfiguration = new WindowConfiguration();
 }
Пример #8
0
        public CocoaWebview(WindowConfiguration config, IContentProvider contentProvider, WebviewBridge bridge)
        {
            this.config          = config ?? throw new ArgumentNullException(nameof(config));
            this.contentProvider = contentProvider ?? throw new ArgumentNullException(nameof(contentProvider));
            this.bridge          = bridge ?? throw new ArgumentNullException(nameof(bridge));

            Interlocked.Increment(ref count);

            // need to keep the delegates around or they will get garbage collected
            loadDelegate                 = LoadCallback;
            loadFailedDelegate           = LoadFailedCallback;
            observedValueChangedDelegate = ObservedValueChanged;
            scriptDelegate               = ScriptCallback;
            uriSchemeStartDelegate       = UriSchemeStartCallback;
            uriSchemeStopDelegate        = UriSchemeStopCallback;


            IntPtr configuration = WebKit.Call("WKWebViewConfiguration", "new");
            IntPtr manager       = ObjC.Call(configuration, "userContentController");
            IntPtr callbackClass = CreateCallbackClass();

            customHost = CreateSchemeHandler(configuration);

            if (config.EnableScriptInterface)
            {
                ObjC.Call(manager, "addScriptMessageHandler:name:", callbackClass, NSString.Create("external"));
                IntPtr script = WebKit.Call("WKUserScript", "alloc");
                ObjC.Call(
                    script,
                    "initWithSource:injectionTime:forMainFrameOnly:",
                    NSString.Create(Resources.GetInitScript("Mac")),
                    IntPtr.Zero,
                    IntPtr.Zero);
                ObjC.Call(manager, "addUserScript:", script);
            }

            Handle = WebKit.Call("WKWebView", "alloc");
            ObjC.Call(Handle, "initWithFrame:configuration:", CGRect.Zero, configuration);
            ObjC.Call(Handle, "setNavigationDelegate:", callbackClass);

            IntPtr bgColor = NSColor.FromHex(config.BackgroundColor);

            ObjC.Call(Handle, "setBackgroundColor:", bgColor);

            IntPtr boolValue = Foundation.Call("NSNumber", "numberWithBool:", 0);

            ObjC.Call(Handle, "setValue:forKey:", boolValue, NSString.Create("drawsBackground"));

            if (config.UseBrowserTitle)
            {
                ObjC.Call(Handle, "addObserver:forKeyPath:options:context:", callbackClass, NSString.Create("title"), IntPtr.Zero, IntPtr.Zero);
            }

            if (enableDevTools)
            {
                var preferences = ObjC.Call(configuration, "preferences");
                ObjC.Call(preferences, "setValue:forKey:", new IntPtr(1), NSString.Create("developerExtrasEnabled"));
            }
        }
Пример #9
0
#pragma warning disable VSTHRD100 // Avoid async void methods
        protected override async void OnStartup(StartupEventArgs e)
#pragma warning restore VSTHRD100 // Avoid async void methods
        {
            var assembly     = typeof(App).Assembly;
            var windowConfig = WindowConfiguration.CreateWithDefaultIcon(assembly, "Website Download System");
            var appConfig    = new WpfAppConfiguration(assembly, windowConfig);
            await AppStartService.StartAppAsync(appConfig);
        }
Пример #10
0
        public CocoaWindow(WindowConfiguration config, IUiFactory windowFactory)
        {
            if (windowFactory == null)
            {
                throw new ArgumentNullException(nameof(windowFactory));
            }

            this.config = config ?? throw new ArgumentNullException(nameof(config));

            Interlocked.Increment(ref count);

            // need to keep the delegates around or they will get garbage collected
            windowShouldCloseDelegate = WindowShouldCloseCallback;
            windowWillCloseDelegate   = WindowWillCloseCallback;

            Handle = AppKit.Call("NSWindow", "alloc");

            var style = NSWindowStyleMask.Titled | NSWindowStyleMask.Closable | NSWindowStyleMask.Miniaturizable;

            if (config.CanResize)
            {
                style |= NSWindowStyleMask.Resizable;
            }

            ObjC.SendMessage(
                Handle,
                ObjC.RegisterName("initWithContentRect:styleMask:backing:defer:"),
                new CGRect(0, 0, config.Width, config.Height),
                (int)style,
                2,
                0);

            Title = config.Title;

            IntPtr bgColor = NSColor.FromHex(config.BackgroundColor);

            ObjC.Call(Handle, "setBackgroundColor:", bgColor);

            var contentProvider = new EmbeddedFileProvider(config.ContentAssembly, config.ContentFolder);

            bridge  = new WebviewBridge();
            webview = new CocoaWebview(config, contentProvider, bridge);
            ObjC.Call(Handle, "setContentView:", webview.Handle);

            if (config.EnableScriptInterface)
            {
                bridge.Init(this, webview, windowFactory);
            }

            if (config.UseBrowserTitle)
            {
                webview.TitleChanged += Webview_TitleChanged;
                bridge.TitleChanged  += Webview_TitleChanged;
            }

            SetWindowDelegate(Handle);
        }
Пример #11
0
        public WinFormsWindow(WindowConfiguration config, IUiFactory windowFactory)
        {
            if (windowFactory == null)
            {
                throw new ArgumentNullException(nameof(windowFactory));
            }

            this.config = config ?? throw new ArgumentNullException(nameof(config));

            bridge = new WebviewBridge();
            var contentProvider = new EmbeddedFileProvider(config.ContentAssembly, config.ContentFolder);

            if (!config.ForceWindowsLegacyWebview && IsEdgeAvailable())
            {
                webview = new WinFormsWebview(config, contentProvider, bridge);
            }
            else
            {
                string hostAddress;
                if (string.IsNullOrWhiteSpace(config.ExternalHost))
                {
                    server = new ContentServer(contentProvider);
                    server.Start();
                    hostAddress = server.HostAddress;
                }
                else
                {
                    hostAddress = config.ExternalHost;
                }

                webview = new WinFormsLegacyWebview(config, hostAddress, bridge);
            }

            webview.Control.Location = new Point(0, 0);
            webview.Control.Dock     = DockStyle.Fill;
            Controls.Add(webview.Control);

            Text      = config.Title;
            Width     = config.Width;
            Height    = config.Height;
            CanResize = config.CanResize;

            ColorTools.ParseHex(config.BackgroundColor, out byte r, out byte g, out byte b);
            BackColor = Color.FromArgb(r, g, b);

            if (config.EnableScriptInterface)
            {
                bridge.Init(this, webview, windowFactory);
            }

            if (config.UseBrowserTitle)
            {
                bridge.TitleChanged += Webview_TitleChanged;
            }

            SetIcon(config.Icon);
        }
 public static void Store(WindowConfiguration config)
 {
     Properties.Settings.Default.Left = config.Left;
     Properties.Settings.Default.Top = config.Top;
     Properties.Settings.Default.Width= config.Width;
     Properties.Settings.Default.Height = config.Height;
     Properties.Settings.Default.IsMaximized = config.State == WindowState.Maximized;
     Properties.Settings.Default.IsMinimized = config.State == WindowState.Minimized;
     Properties.Settings.Default.Save();
 }
Пример #13
0
        public GtkWindow(WindowConfiguration config, IUiFactory windowFactory)
        {
            if (windowFactory == null)
            {
                throw new ArgumentNullException(nameof(windowFactory));
            }

            this.config = config ?? throw new ArgumentNullException(nameof(config));

            var contentProvider = new EmbeddedFileProvider(config.ContentAssembly, config.ContentFolder);

            bridge  = new WebviewBridge();
            webview = new GtkWebview(config, contentProvider, bridge);
            Handle  = Gtk.Window.Create(GtkWindowType.Toplevel);

            Title = config.Title;
            Gtk.Window.SetResizable(Handle, config.CanResize);
            Gtk.Window.SetDefaultSize(Handle, config.Width, config.Height);

            string backgroundColor = config.BackgroundColor;

            if (string.IsNullOrWhiteSpace(backgroundColor))
            {
                backgroundColor = "#FFFFFF";
            }
            SetBackgroundColor(backgroundColor);

            IntPtr scroller = Gtk.Window.CreateScrolled(IntPtr.Zero, IntPtr.Zero);

            Gtk.Widget.ContainerAdd(Handle, scroller);
            Gtk.Widget.ContainerAdd(scroller, webview.Handle);

            // need to keep the delegates around or they will get garbage collected
            deleteDelegate  = DeleteCallback;
            destroyDelegate = DestroyCallback;

            GLib.ConnectSignal(Handle, "delete-event", deleteDelegate, IntPtr.Zero);
            GLib.ConnectSignal(Handle, "destroy", destroyDelegate, IntPtr.Zero);

            webview.CloseRequested += Webview_CloseRequested;

            if (config.EnableScriptInterface)
            {
                bridge.Init(this, webview, windowFactory);
            }

            if (config.UseBrowserTitle)
            {
                webview.TitleChanged += Webview_TitleChanged;
                bridge.TitleChanged  += Webview_TitleChanged;
            }

            SetIcon(config.Icon);
        }
Пример #14
0
        public void Initialise(WindowConfiguration configuration)
        {
            Configuration = new SystemConfiguration(configuration);

            InitialiseWindows(configuration.Title);

            Window = new Window();
            Window.Initialise(configuration.Size, _renderForm.Handle);

            _timer = new Timer();
            _timer.Initialise();
        }
Пример #15
0
 public TimeService(ILogger <TimeService> logger, NtpConfiguration ntpConfiguration,
                    WindowConfiguration windowConfiguration, DateAndTimeFormat dateAndTimeFormat,
                    ApplicationConfiguration applicationConfiguration, IStopwatchService stopwatchService, INicService nicService)
 {
     _logger                   = logger;
     _ntpConfiguration         = ntpConfiguration;
     _windowConfiguration      = windowConfiguration;
     _dateAndTimeFormat        = dateAndTimeFormat;
     _applicationConfiguration = applicationConfiguration;
     _stopwatchService         = stopwatchService;
     _nicService               = nicService;
 }
Пример #16
0
        public async Task <IWindow> CreateWindow(string windowXaml)
        {
            var request = new WindowConfiguration()
            {
                Xaml        = windowXaml,
                FitToScreen = true
            };

            LogMessage?.Invoke($"{nameof(IApp)}.{nameof(CreateWindow)}(...)");
            if (await Client.CreateWindowAsync(request) is { } reply)
            {
                if (LogMessage is { })
Пример #17
0
        public GameInitializor()
        {
            windowConfiguration = new WindowConfiguration()
            {
                Height = 30,
                Width  = 90
            };

            this.projectSettings = new ProjectSettings(windowConfiguration);
            this.mainMenu        = new MainMenu();
            this.combatScreen    = new CombatScreen();
            this.controls        = new Controls();
        }
Пример #18
0
        void Awake()
        {
            if (imageBox == null)
            {
                imageBox = FindObjectOfType <RawImage>();
            }
            if (window == null)
            {
                window = FindObjectOfType <WindowConfiguration>();
            }

            UpdateConfiguration();
        }
Пример #19
0
        public static void Main(string[] args)
        {
            // Note: Program.cs is shared between all projects for convenience.
            // You could just as well have a separate startup logic for each platform.

            // this creates a new app configuration with default values
            var config = new WindowConfiguration();

            // this relates to the path defined in the shared .proj file
            config.ContentFolder = "App";

            // runs the application and opens a window with the given page loaded
            Application.Run(config, "index.html");
        }
Пример #20
0
        public WinFormsWebview(WindowConfiguration config, IContentProvider contentProvider, WebviewBridge bridge)
        {
            if (contentProvider == null)
            {
                throw new ArgumentNullException(nameof(contentProvider));
            }

            this.config    = config ?? throw new ArgumentNullException(nameof(config));
            this.bridge    = bridge ?? throw new ArgumentNullException(nameof(bridge));
            streamResolver = new EdgeUriToStreamResolver(contentProvider);

            Layout += (s, e) => UpdateSize();

            Init();
        }
Пример #21
0
        protected override void Configure()
        {
            if (_container == null) //iOC Registration
            {
                _container = new WinRTContainer();
            }
            _container.RegisterWinRTServices();

            //Register all internal services
            RegisterInternalServices.RegisterViewModels(ref _container);
            RegisterInternalServices.RegisterSqliteEncryption(ref _container); //Enable Encryption on the Sqlite Storage
            Subscriptions();

            //UI Configuration
            WindowConfiguration.ConfigureApplicationShell();
        }
Пример #22
0
        public BaseDialog(PlaylistSource queue, string title, WindowConfiguration windowConfig) : base(title)
        {
            this.queue   = queue;
            VBox.Spacing = 6;

            HBox filter_box = new HBox();

            filter_box.Spacing = 6;

            Label search_label = new Label("_Search:");

            filter_box.PackStart(search_label, false, false, 0);

            search_entry = new MuinsheeSearchEntry();
            search_entry.Show();
            search_entry.Changed += OnFilterChanged;
            search_entry.Ready    = true;
            OnFilterChanged(null, null);
            filter_box.PackStart(search_entry, true, true, 0);

            VBox.PackStart(filter_box, false, false, 0);

            Hyena.Widgets.ScrolledWindow sw = new Hyena.Widgets.ScrolledWindow();
            sw.Add(GetItemWidget());
            VBox.PackStart(sw, true, true, 0);

            AddDefaultCloseButton();

            Button queue_button = new ImageButton(Catalog.GetString("En_queue"), "gtk-add");

            AddActionWidget(queue_button, Gtk.ResponseType.Apply);

            Button play_button = new ImageButton(Catalog.GetString("_Play"), "media-playback-start");

            AddButton(play_button, Gtk.ResponseType.Ok, true);

            window_controller = new PersistentWindowController(this, windowConfig, WindowPersistOptions.Size);
            window_controller.Restore();
            ShowAll();

            Response += OnResponse;
        }
Пример #23
0
        /// <summary> "Configuration..." menu item </summary>
        private void menuItemConfigurationOnClick(object sender, EventArgs eventArgs)
        {
            foreach (Window window in Application.Current.Windows)
            {
                if (window is WindowConfiguration)
                {
                    window.Activate();
                    return;
                }
            }

            var win = new WindowConfiguration();

            win.OnCloseWindowSettings += saved =>
            {
                DataManager.OpenConfiguration();
                setWindowVisibilityBehaviour(saved && !_listWindowIsShown);
            };
            win.Show();
        }
Пример #24
0
        public static void Main(string[] args)
        {
            // Note: Program.cs is shared between all projects for convenience.
            // You could just as well have a separate startup logic for each platform.

            // this creates a new configuration with default values
            var config = new WindowConfiguration();
            var icon   = AppIcon.FromFile("icon", "Icons");

            // we have a separate assembly for the client side files
            config.ContentAssembly = typeof(DummyMarker).Assembly;
            // this relates to the path defined in the client .csproj file
            config.ContentFolder = "Angular\\dist";
            config.Icon          = icon;

            // this is only called in Debug mode:
            SetDevServer(config);

            // runs the application and opens a window with the given page loaded
            Application.Run(config, "index.html");
        }
        public static WindowConfiguration Restore()
        {
            var config = new WindowConfiguration
                {
                    Left = Properties.Settings.Default.Left,
                    Top = Properties.Settings.Default.Top,
                    Width = Properties.Settings.Default.Width,
                    Height = Properties.Settings.Default.Height,
                };
            if (Properties.Settings.Default.IsMaximized)
                config.State = WindowState.Maximized;
            else if (Properties.Settings.Default.IsMinimized)
                config.State = WindowState.Minimized;
            else
                config.State = WindowState.Normal;

            if (config.Width == 0 || config.Height == 0)
                return null;

            return config;
        }
        public WinFormsLegacyWebview(WindowConfiguration config, string hostAddress, WebviewBridge scriptingApi)
        {
            if (scriptingApi == null)
            {
                throw new ArgumentNullException(nameof(scriptingApi));
            }

            this.config      = config ?? throw new ArgumentNullException(nameof(config));
            this.hostAddress = hostAddress ?? throw new ArgumentNullException(nameof(hostAddress));

            webview = new WebBrowser();
            webview.IsWebBrowserContextMenuEnabled = false;

            if (config.EnableScriptInterface)
            {
                scriptInterface            = new ScriptInterface(scriptingApi);
                webview.ObjectForScripting = scriptInterface;
            }

            webview.DocumentCompleted += Webview_DocumentCompleted;
        }
Пример #27
0
        public ApplicationService(ILogger <ApplicationService> logger, ITimeService timeService,
                                  IWindowService windowService, DateAndTimeFormat dateAndTimeFormat, WindowConfiguration windowConfiguration,
                                  ApplicationConfiguration applicationConfiguration, IStopwatchService stopwatchService, IHostApplicationLifetime hostApplicationLifetime,
                                  IStorageService storageService, INicService nicService, IInternetService internetService)
        {
            _logger                   = logger;
            _timeService              = timeService;
            _windowService            = windowService;
            _dateAndTimeFormat        = dateAndTimeFormat;
            _windowConfiguration      = windowConfiguration;
            _applicationConfiguration = applicationConfiguration;
            _stopwatchService         = stopwatchService;
            _hostApplicationLifetime  = hostApplicationLifetime;
            _storageService           = storageService;
            _nicService               = nicService;
            _internetService          = internetService;

            _internetService.InternetConnectionAvailable += _internetService_InternetConnectionAvailable;

            _hostApplicationLifetime.ApplicationStopping.Register(() =>
            {
                if (_applicationConfiguration.CountSystemRunningTime)
                {
                    _stopwatchService.StopTimer();
                }

                if (_applicationConfiguration.CountNetworkActivity)
                {
                    _nicService.StopNicsMonitoring();
                }

                _storageService.EditData();

                _logger.LogDebug("Shutting down application");
                _logger.LogDebug(new string('-', 100));
            });
        }
    public static void Load(Window window, WindowConfiguration settings)
    {
        if (!double.IsNaN(settings.Width))
        {
            window.Width = settings.Width;
        }

        if (!double.IsNaN(settings.Height))
        {
            window.Height = settings.Height;
        }

        if (!double.IsNaN(settings.X) && !double.IsNaN(settings.Y))
        {
            window.Position = new PixelPoint((int)settings.X, (int)settings.Y);
            window.WindowStartupLocation = WindowStartupLocation.Manual;
        }
        else
        {
            window.WindowStartupLocation = WindowStartupLocation.CenterScreen;
        }

        window.WindowState = settings.WindowState;
    }
 public WindowService(ILogger <WindowService> logger, WindowConfiguration windowConfiguration)
 {
     _logger = logger;
     _windowConfiguration = windowConfiguration;
 }
Пример #30
0
 internal ShellWindowConfiguration(WindowConfiguration configuration)
 {
     _configuration = configuration;
 }
Пример #31
0
 public DashmanWindow(WindowConfiguration windowConfig)
 {
     _windowConfig = windowConfig;
     InitializeComponent();
 }
Пример #32
0
        private async Task <Window> CreateWindow <TResult>(Func <TResult, Task> callback1, Func <Task> callback2, FrameworkElement view, IViewModel viewModel)
        {
            var window = Common.CreateWindow(ref this.windowType);

            window.BeginInit();

            // Special stuff for splashscreens
            if (viewModel is ApplicationBase)
            {
                window.Tag = SplashScreenWindowTag;
                WindowConfiguration.SetHasOwner(view, false);
                WindowConfiguration.SetSizeToContent(view, SizeToContent.WidthAndHeight);
                WindowConfiguration.SetShowInTaskbar(view, false);
                WindowConfiguration.SetWindowStartupLocation(view, WindowStartupLocation.CenterScreen);
                WindowConfiguration.SetWindowStyle(view, WindowStyle.None);
                WindowConfiguration.SetResizeMode(view, ResizeMode.NoResize);
                WindowConfiguration.SetIcon(view, null);
                WindowConfiguration.SetTitle(view, null);
            }

            // Add this new window to the dictionary
            windows.Add(new WindowViewModelObject {
                window = window, viewModelId = viewModel.Id
            });
            window.ResizeMode  = WindowConfiguration.GetResizeMode(view);
            window.WindowStyle = WindowConfiguration.GetWindowStyle(view);

            window.Width                 = WindowConfiguration.GetWidth(view);
            window.Height                = WindowConfiguration.GetHeight(view);
            window.MaxHeight             = WindowConfiguration.GetMaxHeight(view);
            window.MinHeight             = WindowConfiguration.GetMinHeight(view);
            window.MaxWidth              = WindowConfiguration.GetMaxWidth(view);
            window.MinWidth              = WindowConfiguration.GetMinWidth(view);
            window.ShowInTaskbar         = WindowConfiguration.GetShowInTaskbar(view);
            window.Topmost               = WindowConfiguration.GetTopmost(view);
            window.WindowStartupLocation = WindowConfiguration.GetWindowStartupLocation(view);
            window.WindowState           = WindowConfiguration.GetWindowState(view);
            window.SizeToContent         = WindowConfiguration.GetSizeToContent(view);

            // Add the inputbindings to the window we have to recreate the binding here because the
            // sources are all wrong

            foreach (InputBinding inputBinding in view.InputBindings)
            {
                var oldBinding = BindingOperations.GetBinding(inputBinding, InputBinding.CommandProperty);
                var newBinding = oldBinding.Clone();
                newBinding.Source = viewModel;
                BindingOperations.ClearBinding(inputBinding, InputBinding.CommandProperty);
                BindingOperations.SetBinding(inputBinding, InputBinding.CommandProperty, newBinding);

                window.InputBindings.Add(inputBinding);
            }
            // remove them from the view
            view.InputBindings.Clear();

            if (WindowConfiguration.GetIsWindowPersistent(view))
            {
                PersistentWindowInformation.Load(window, viewModel.GetType());
            }

            // set the window owner
            if (window.Tag != SplashScreenWindowTag && WindowConfiguration.GetHasOwner(view) && Application.Current.MainWindow.Tag != SplashScreenWindowTag)
            {
                windows.FirstOrDefault(x => x.window.IsActive).IsNotNull(x => window.Owner = x?.window);
            }

            //if (Application.Current.MainWindow != null && Application.Current.MainWindow.Tag == SplashScreenWindowTag)
            //    Application.Current.MainWindow = window;

            window.SetBinding(Window.IconProperty, new Binding {
                Path = new PropertyPath(WindowConfiguration.IconProperty), Source = view
            });
            window.SetBinding(Window.TitleProperty, new Binding {
                Path = new PropertyPath(WindowConfiguration.TitleProperty), Source = view
            });

            if (window.Icon == null && window.Tag != SplashScreenWindowTag)
            {
                window.Icon = await UnsafeNative.ExtractAssociatedIcon(Assembly.GetEntryAssembly().Location).ToBitmapImageAsync();
            }

            if (viewModel is IFrameAware frameAware)
            {
                window.Activated   += (s, e) => frameAware.Activated();
                window.Deactivated += (s, e) => frameAware.Deactivated();
            }

            if (viewModel is ISizeAware sizeAware)
            {
                window.SizeChanged += (s, e) => sizeAware.SizeChanged(e.NewSize.Width, e.NewSize.Height);
            }

            window.SizeChanged += (s, e) =>
            {
                if (window.WindowState == WindowState.Normal)
                {
                    PersistentWindowProperties.SetHeight(window, e.NewSize.Height);
                    PersistentWindowProperties.SetWidth(window, e.NewSize.Width);
                }
            };
            window.Closing += Window_Closing;
            window.Closed  += (s, e) =>
            {
                windows.Remove(x => x.window == s);

                if (callback1 != null)
                {
                    (viewModel as IDialogViewModel <TResult>).IsNotNull(async x => await callback1(x.Result));
                }

                if (callback2 != null)
                {
                    (viewModel as IDialogViewModel).IsNotNull(async x => await callback2());
                }

                window.Content.As <FrameworkElement>()?.DataContext.TryDispose();

                window.Content.TryDispose();
                window.Content = null;
                window.TryDispose(); // some custom windows have implemented the IDisposable interface
            };

            // make sure the datacontext of the window is correct
            view.DataContextChanged += (s, e) => window.DataContext = view.DataContext;

            window.Content   = view;
            view.DataContext = viewModel;

            if (viewModel is IViewAware viewAwareViewModel)
            {
                viewAwareViewModel.OnAssignToDataContext(window.InputBindings);
            }

            Common.AddTransistionStoryboard(view);
            window.EndInit();

            return(window);
        }
Пример #33
0
 private async Task <Tuple <Window, bool> > CreateDefaultWindow <TResult>(Func <TResult, Task> callback1, Func <Task> callback2, FrameworkElement view, IViewModel viewModel) =>
 new Tuple <Window, bool>(await this.CreateWindow(callback1, callback2, view, viewModel), WindowConfiguration.GetIsModal(view));
Пример #34
0
 static Config()
 {
     Window = new WindowConfiguration();
     Injection = new InjectionConfiguration();
 }
 public WindowConfigurationNodeFactory(WindowConfiguration windowConfiguration)
 {
     _windowConfiguration = windowConfiguration;
 }