Example #1
0
        public WpfApplicationHost()
        {
            WpfValueConverter       wpfValueConverter       = new WpfValueConverter();
            WpfRenderElementFactory wpfRenderElementFactory = new WpfRenderElementFactory(wpfValueConverter);

            PresentationSourceFactory = new WpfPresentationSourceFactory(wpfRenderElementFactory, wpfValueConverter);
            TaskScheduler             = new WpfTaskScheduler();
            TextMeasurementService    = new WpfTextMeasurementService(wpfValueConverter);

            wpf::System.Windows.Application application = new wpf::System.Windows.Application();
        }
Example #2
0
        public WebApplicationHost()
        {
            RenderQueue                   renderQueue                   = new RenderQueue();
            HtmlValueConverter            htmlValueConverter            = new HtmlValueConverter();
            SvgValueConverter             svgValueConverter             = new SvgValueConverter();
            SvgDefinitionContainer        svgDefinitionContainer        = new SvgDefinitionContainer(renderQueue);
            ImageElementContainer         imageElementContainer         = new ImageElementContainer();
            EmbeddedResourceObjectFactory embeddedResourceObjectFactory = new EmbeddedResourceObjectFactory(htmlValueConverter);

            HtmlRenderElementFactory htmlRenderElementFactory = new HtmlRenderElementFactory(renderQueue, htmlValueConverter, imageElementContainer, embeddedResourceObjectFactory, svgValueConverter, svgDefinitionContainer);

            PresentationSourceFactory = new PresentationSourceFactory(htmlRenderElementFactory, htmlValueConverter, imageElementContainer, svgDefinitionContainer);
            TaskScheduler             = new TaskScheduler();
            TextMeasurementService    = new TextMeasurementService(htmlValueConverter);
        }
Example #3
0
        public Application()
        {
            // Keep a reference to the app:
            Application.Current = this;

            // Initialize Deployment
            _ = Deployment.Current;

            // In case of a redirection from Microsoft AAD, when running in the Simulator, we re-instantiate the application. We need to reload the JavaScript files because they are no longer in the HTML DOM due to the AAD redirection:
            INTERNAL_InteropImplementation.ResetLoadedFilesDictionaries();

#if CSHTML5BLAZOR
            // we change the resource manager for every resource registered
            ClientSideResourceRegister.Startup();
#endif
            // Keep a reference to the startup assembly:
            StartupAssemblyInfo.StartupAssembly = this.GetType().Assembly;

            // Remember whether we are in "SL Migration" mode or not:
#if MIGRATION
            CSHTML5.Interop.ExecuteJavaScript(@"document.isSLMigration = true");
#else
            CSHTML5.Interop.ExecuteJavaScript(@"document.isSLMigration = false");
#endif

            //Interop.ExecuteJavaScript("document.raiseunhandledException = $0", (Action<object>)RaiseUnhandledException);


            // Inject the "DataContractSerializer" into the "XmlSerializer" (read note in the "XmlSerializer" implementation to understand why):
#if OPENSILVER
            if (false)                                    //Note: in case of the Simulator, we reference the .NET Framework version of "System.xml.dll", so we cannot inject stuff because the required members of XmlSerializer would be missing.
#elif BRIDGE
            if (!CSHTML5.Interop.IsRunningInTheSimulator) //Note: in case of the Simulator, we reference the .NET Framework version of "System.xml.dll", so we cannot inject stuff because the required members of XmlSerializer would be missing.
#endif
            {
                InjectDataContractSerializerIntoXmlSerializer();
            }

#if !CSHTML5NETSTANDARD
            // Fix the freezing of the Simulator when calling 'alert' using the "Interop.ExecuteJavaScript()" method by redirecting the JavaScript "alert" to the Simulator message box:
            if (CSHTML5.Interop.IsRunningInTheSimulator)
            {
                RedirectAlertToMessageBox_SimulatorOnly();
            }
#endif

            // Get default font-family from css
            INTERNAL_FontsHelper.DefaultCssFontFamily = Convert.ToString(CSHTML5.Interop.ExecuteJavaScript("window.getComputedStyle(document.getElementsByTagName('body')[0]).getPropertyValue(\"font-family\")"));


            TextMeasurementService = new TextMeasurementService();

            // Initialize the window:
            if (_mainWindow == null) // Note: it could be != null if the user clicks "Restart" from the Simulator advanced options.
            {
                _mainWindow    = new Window();
                Window.Current = _mainWindow;
                object applicationRootDomElement = INTERNAL_HtmlDomManager.GetApplicationRootDomElement();
                _mainWindow.AttachToDomElement(applicationRootDomElement);

                // Listen to clicks anywhere in the window (this is used to close the popups that are not supposed to stay open):
#if MIGRATION
                _mainWindow.AddHandler(UIElement.MouseLeftButtonDownEvent, new MouseButtonEventHandler(INTERNAL_PopupsManager.OnClickOnPopupOrWindow), true);
#else
                _mainWindow.AddHandler(UIElement.PointerPressedEvent, new PointerEventHandler(INTERNAL_PopupsManager.OnClickOnPopupOrWindow), true);
#endif

#if !CSHTML5NETSTANDARD
                // Workaround an issue on Firefox where the UI disappears if the window is resized and on some other occasions:
                if (INTERNAL_HtmlDomManager.IsFirefox())
                {
                    _mainWindow.SizeChanged += MainWindow_SizeChanged;
                    _timerForWorkaroundFireFoxIssue.Interval = new TimeSpan(0, 0, 2);
                    _timerForWorkaroundFireFoxIssue.Tick    += TimerForWorkaroundFireFoxIssue_Tick;
                }
#endif
            }

            // We call the "Startup" event and the "OnLaunched" method using the Dispatcher, because usually the user registers the "Startup" event in the constructor of the "App.cs" class, which is derived from "Application.cs", and therefore when we arrive here the event is not yet registered. Executing the code in the Dispatcher ensures that the constructor of the "App.cs" class has finished before running the code.
#if MIGRATION
            Dispatcher
#else
            CoreDispatcher
#endif
            .INTERNAL_GetCurrentDispatcher().BeginInvoke((Action)(() =>
            {
                StartAppServices();

                // Raise the "Startup" event:
                if (this.Startup != null)
                {
                    Startup(this, new StartupEventArgs());
                }

                // Call the "OnLaunched" method:
                this.OnLaunched(new LaunchActivatedEventArgs());
            }));
        }
 public WordWrapService(ITextMeasurementService textMeasurementService)
 {
     _tms = textMeasurementService;
 }
Example #5
0
 public TestApplicationHost()
 {
     TaskScheduler          = new TestTaskScheduler();
     TextMeasurementService = new TestTextMeasurementService();
 }