Beispiel #1
0
        public static void Reset()
        {
            lock (lockObject)
            {
                if (initialized == false)
                {
                    return;
                }

                //VisualTreeHelper.SubTreeAdded -= VisualTreeHelper_ChildAdded;
                //VisualTreeHelper.SubTreeRemoved -= VisualTreeHelper_ChildRemoved;

                //VisualTreeHelper.Reset();
                LoadedDetectionHelper.Reset();

                uiTimer?.Cancel();
                uiTimer?.Dispose();
                uiTimer = null;

                instance = null;

                initialized = false;
            }
        }
Beispiel #2
0
        public static void Initialize(Element rootElement, Assembly[] resourceSearchAssemblies = null, IDictionary <string, List <string> > cssNamespaceMapping = null)
        {
            lock (lockObject)
            {
                if (initialized &&
                    rootElement == Css.rootElement)
                {
                    return;
                }

                Reset();

                cssNamespaceMapping = cssNamespaceMapping ?? DefaultCssNamespaceMapping;

                TypeHelpers.Initialze(cssNamespaceMapping, true);

                var defaultCssNamespace       = cssNamespaceMapping.Keys.First();
                var markupExtensionParser     = new MarkupExtensionParser();
                var dependencyPropertyService = new DependencyPropertyService();
                var cssTypeHelper             = new CssTypeHelper <BindableObject, BindableProperty, Style>(markupExtensionParser, dependencyPropertyService);

                instance = new BaseCss <BindableObject, Style, BindableProperty>(
                    dependencyPropertyService,
                    new TreeNodeProvider(dependencyPropertyService),
                    new StyleResourceService(),
                    new StyleService(dependencyPropertyService, markupExtensionParser),
                    defaultCssNamespace,
                    markupExtensionParser,
                    Device.BeginInvokeOnMainThread,
                    new CssFileProvider(resourceSearchAssemblies ?? new Assembly[0], cssTypeHelper)
                    );

                Css.rootElement = rootElement;

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

                LoadedDetectionHelper.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;
            }
        }