Example #1
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;
            }
        }
Example #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;
            }
        }
Example #3
0
        public static void Initialize(Element rootElement, Assembly[] resourceSearchAssemblies = null)
        {
            lock (lockObject)
            {
                if (initialized &&
                    rootElement == Css.rootElement)
                {
                    return;
                }

                Reset();

                var mapping = new Dictionary <string, List <string> >
                {
                    {
                        "http://xamarin.com/schemas/2014/forms",
                        new List <string>
                        {
                            typeof(Xamarin.Forms.Button).AssemblyQualifiedName.Replace(".Button,", ","),
                        }
                    }
                };

                TypeHelpers.Initialze(mapping, true);

                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 LogicalTreeNodeProvider(dependencyPropertyService),
                    new StyleResourceService(),
                    new StyleService(dependencyPropertyService, markupExtensionParser),
                    DomElementBase <BindableObject, Element> .GetAssemblyQualifiedNamespaceName(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;
            }
        }