Esempio n. 1
0
        public static void Initialize(IEnumerable <Assembly> resourceSearchAssemblies)
        {
            if (initialized)
            {
                return;
            }

            instance = new BaseCss <DependencyObject, DependencyObject, Style, DependencyProperty>(
                new DependencyPropertyService(),
                new LogicalTreeNodeProvider(new DependencyPropertyService()),
                new StyleResourceService(),
                new StyleService(new DependencyPropertyService()),
                DomElementBase <DependencyObject, DependencyProperty> .GetPrefix(typeof(Button)),
                new MarkupExtensionParser(),
                RunOnUIThread,
                new CssFileProvider(resourceSearchAssemblies)
                );

            LoadedDetectionHelper.Initialize();

            LoadedDetectionHelper.SubTreeAdded   += LoadedDetectionHelper_SubTreeAdded;
            LoadedDetectionHelper.SubTreeRemoved += LoadedDetectionHelper_SubTreeRemoved;

            CompositionTarget.Rendering += RenderingHandler;

            initialized = true;
        }
Esempio n. 2
0
        public static void Initialize()
        {
            if (initialized)
            {
                return;
            }

            initialized = true;

            var dispatcher = Application.Current?.Dispatcher ?? Dispatcher.CurrentDispatcher;
            IDependencyPropertyService <DependencyObject, DependencyObject, Style, DependencyProperty> dependencyPropertyService =
                new DependencyPropertyService();
            var visualTreeNodeProvider  = new VisualTreeNodeProvider(dependencyPropertyService);
            var logicalTreeNodeProvider = new LogicalTreeNodeProvider(dependencyPropertyService);
            var markupExtensionParser   = new MarkupExtensionParser();
            var cssTypeHelper           = new CssTypeHelper <DependencyObject, DependencyObject, DependencyProperty, Style>(markupExtensionParser, dependencyPropertyService);

            instance = new BaseCss <DependencyObject, DependencyObject, Style, DependencyProperty>(
                dependencyPropertyService,
                new SwitchableTreeNodeProvider(
                    dependencyPropertyService,
                    new VisualWithLogicalFallbackTreeNodeProvider(dependencyPropertyService, visualTreeNodeProvider, logicalTreeNodeProvider),
                    logicalTreeNodeProvider),
                new StyleResourceService(),
                new StyleService(new DependencyPropertyService(), new MarkupExtensionParser()),
                DomElementBase <DependencyObject, DependencyProperty> .GetPrefix(typeof(System.Windows.Controls.Button)),
                markupExtensionParser,
                dispatcher.Invoke,
                new CssFileProvider(cssTypeHelper)
                );

            CompositionTarget.Rendering += RenderingHandler();

            LoadedDetectionHelper.Initialize();
        }
Esempio n. 3
0
        public static void Initialize(Element rootElement, Assembly[] resourceSearchAssemblies = null)
        {
            lock (lockObject)
            {
                if (initialized &&
                    rootElement == Css.rootElement)
                {
                    return;
                }

                Reset();

                var markupExtensionParser     = new MarkupExtensionParser();
                var dependencyPropertyService = new DependencyPropertyService();
                var cssTypeHelper             = new CssTypeHelper <BindableObject, BindableObject, BindableProperty, Style>(markupExtensionParser, dependencyPropertyService);

                instance = new BaseCss <BindableObject, BindableObject, Style, BindableProperty>(
                    dependencyPropertyService,
                    new LogicalTreeNodeProvider(dependencyPropertyService),
                    new StyleResourceService(),
                    new StyleService(dependencyPropertyService, markupExtensionParser),
                    DomElementBase <BindableObject, Element> .GetPrefix(typeof(Button)),
                    markupExtensionParser,
                    Device.BeginInvokeOnMainThread,
                    new CssFileProvider(resourceSearchAssemblies ?? new Assembly[0], cssTypeHelper)
                    );

                Css.rootElement = rootElement;

                VisualTreeHelper.SubTreeAdded   += VisualTreeHelper_ChildAdded;
                VisualTreeHelper.SubTreeRemoved += VisualTreeHelper_ChildRemoved;

                VisualTreeHelper.Initialize(rootElement);

                if (rootElement is Application)
                {
                    var application = rootElement as Application;

                    if (application.MainPage == null)
                    {
                        PropertyChangedEventHandler handler = null;
                        handler = (s, e) =>
                        {
                            if (e.PropertyName == nameof(Application.MainPage))
                            {
                                application.PropertyChanged -= handler;
                                VisualTreeHelper.Include(application.MainPage);
                            }
                        };

                        application.PropertyChanged += handler;
                    }
                }

                StartUiTimer();

                initialized = true;
            }
        }
Esempio n. 4
0
        public static void Initialize(Element rootElement)
        {
            if (initialized &&
                rootElement == Css.rootElement)
            {
                return;
            }

            Reset();

            Css.rootElement = rootElement;

            CssParsing.CssParser.Initialize(DomElementBase <BindableObject, Element> .GetPrefix(typeof(Button)));

            VisualTreeHelper.SubTreeAdded   += VisualTreeHelper_ChildAdded;
            VisualTreeHelper.SubTreeRemoved += VisualTreeHelper_ChildRemoved;

            VisualTreeHelper.Initialize(rootElement);

            if (rootElement is Application)
            {
                var application = rootElement as Application;

                // Workaround: MainPage not initialized on appstart
                Timer workaroundTimer = null;
                workaroundTimer = new Timer(TimeSpan.FromMilliseconds(16), (state) =>
                {
                    if (application.MainPage == null)
                    {
                        return;
                    }

                    Device.BeginInvokeOnMainThread(() =>
                    {
                        VisualTreeHelper.Include(application.MainPage);
                        StartUiTimer();
                    });

                    workaroundTimer.Cancel();
                    workaroundTimer.Dispose();
                }, null);
            }
            else
            {
                StartUiTimer();
            }

            initialized = true;
        }
Esempio n. 5
0
        public static void Initialize()
        {
            if (initialized)
            {
                return;
            }

            initialized = true;

            instance = new BaseCss <DependencyObject, DependencyObject, Style, DependencyProperty>(
                new DependencyPropertyService(),
                new LogicalTreeNodeProvider(new DependencyPropertyService()),
                new StyleResourceService(),
                new StyleService(new DependencyPropertyService(), new MarkupExtensionParser()),
                DomElementBase <DependencyObject, DependencyProperty> .GetPrefix(typeof(System.Windows.Controls.Button)),
                new MarkupExtensionParser(),
                Application.Current.Dispatcher.Invoke,
                new CssFileProvider()
                );

            CompositionTarget.Rendering += RenderingHandler();

            LoadedDetectionHelper.Initialize();
        }