예제 #1
0
파일: Css.cs 프로젝트: cheahengsoon/XamlCSS
        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();
        }
예제 #2
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;
        }
예제 #3
0
파일: Css.cs 프로젝트: cheahengsoon/XamlCSS
        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;
            }
        }
예제 #4
0
        public static void Initialize()
        {
            if (initialized)
            {
                return;
            }

            initialized = true;

            var mapping = new Dictionary <string, List <string> >
            {
                {
                    "http://schemas.microsoft.com/winfx/2006/xaml/presentation",
                    new List <string>
                    {
                        typeof(System.Windows.Data.Binding).AssemblyQualifiedName.Replace(".Binding,", ","),
                        typeof(System.Windows.Navigation.NavigationWindow).AssemblyQualifiedName.Replace(".NavigationWindow,", ","),
                        typeof(System.Windows.Shapes.Rectangle).AssemblyQualifiedName.Replace(".Rectangle,", ","),
                        typeof(System.Windows.Controls.Button).AssemblyQualifiedName.Replace(".Button,", ","),
                        typeof(System.Windows.FrameworkElement).AssemblyQualifiedName.Replace(".FrameworkElement,", ","),
                        typeof(System.Windows.Documents.Run).AssemblyQualifiedName.Replace(".Run,", ",")
                    }
                }
            };

            TypeHelpers.Initialze(mapping);

            CompositionTarget.Rendering += RenderingHandler();

            var dispatcher = Application.Current?.Dispatcher ?? Dispatcher.CurrentDispatcher;
            IDependencyPropertyService <DependencyObject, Style, DependencyProperty> dependencyPropertyService =
                new DependencyPropertyService();
            var visualTreeNodeProvider  = new VisualTreeNodeProvider(dependencyPropertyService);
            var logicalTreeNodeProvider = new LogicalTreeNodeProvider(dependencyPropertyService);
            var visualTreeNodeWithLogicalFallbackProvider = new VisualWithLogicalFallbackTreeNodeProvider(dependencyPropertyService, visualTreeNodeProvider, logicalTreeNodeProvider);
            var markupExtensionParser      = new MarkupExtensionParser();
            var cssTypeHelper              = new CssTypeHelper <DependencyObject, DependencyProperty, Style>(markupExtensionParser, dependencyPropertyService);
            var switchableTreeNodeProvider = new SwitchableTreeNodeProvider(dependencyPropertyService, visualTreeNodeWithLogicalFallbackProvider, logicalTreeNodeProvider);
            var defaultCssNamespace        = DomElementBase <DependencyObject, DependencyProperty> .GetAssemblyQualifiedNamespaceName(typeof(System.Windows.Controls.Button));

            instance = new BaseCss <DependencyObject, Style, DependencyProperty>(
                dependencyPropertyService,
                switchableTreeNodeProvider,
                new StyleResourceService(),
                new StyleService(new DependencyPropertyService(), new MarkupExtensionParser()),
                defaultCssNamespace,
                markupExtensionParser,
                dispatcher.Invoke,
                new CssFileProvider(cssTypeHelper)
                );

            // Warmup(markupExtensionParser, defaultCssNamespace);

            LoadedDetectionHelper.Initialize();
        }
예제 #5
0
파일: Css.cs 프로젝트: mediabuff/XamlCSS
        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;
        }
예제 #6
0
        public static void Initialize(IEnumerable <Assembly> resourceSearchAssemblies)
        {
            if (initialized)
            {
                return;
            }

            var mapping = new Dictionary <string, List <string> >
            {
                {
                    "http://schemas.microsoft.com/winfx/2006/xaml/presentation",
                    new List <string>
                    {
                        typeof(Windows.UI.Xaml.Data.Binding).AssemblyQualifiedName.Replace(".Binding,", ","),
                        typeof(Windows.UI.Xaml.Shapes.Rectangle).AssemblyQualifiedName.Replace(".Rectangle,", ","),
                        typeof(Windows.UI.Xaml.Controls.Button).AssemblyQualifiedName.Replace(".Button,", ","),
                        typeof(Windows.UI.Xaml.FrameworkElement).AssemblyQualifiedName.Replace(".FrameworkElement,", ","),
                        typeof(Windows.UI.Xaml.Documents.Run).AssemblyQualifiedName.Replace(".Run,", ",")
                    }
                }
            };

            TypeHelpers.Initialze(mapping, false);

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

            instance = new BaseCss <DependencyObject, Style, DependencyProperty>(
                dependencyPropertyService,
                new LogicalTreeNodeProvider(dependencyPropertyService),
                new StyleResourceService(),
                new StyleService(dependencyPropertyService),
                DomElementBase <DependencyObject, DependencyProperty> .GetAssemblyQualifiedNamespaceName(typeof(Button)),
                markupExtensionParser,
                RunOnUIThread,
                new CssFileProvider(resourceSearchAssemblies, cssTypeHelper)
                );

            LoadedDetectionHelper.Initialize();

            CompositionTarget.Rendering += RenderingHandler;

            initialized = true;
        }
예제 #7
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();
        }
예제 #8
0
 public NamedNodeList(DomElementBase <DependencyObject, DependencyProperty> node, ITreeNodeProvider <DependencyObject> treeNodeProvider)
     : base(node, treeNodeProvider)
 {
 }
예제 #9
0
파일: TestNode.cs 프로젝트: xathu/XamlCSS
 public TestNamedNodeList(DomElementBase <UIElement, IDictionary <object, object> > node)
     : base(node, null)
 {
 }
예제 #10
0
 public NamedNodeList(DomElementBase <BindableObject, BindableProperty> node, ITreeNodeProvider <BindableObject> treeNodeProvider)
     : base(node, treeNodeProvider)
 {
 }
예제 #11
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;
            }
        }