예제 #1
0
 private static void RenderingHandler(object sender, EventArgs e)
 {
     if (instance?.ExecuteApplyStyles() == true)
     {
         // after the first successful applying remove the handler.
         CompositionTarget.Rendering -= RenderingHandler;
     }
 }
예제 #2
0
파일: Css.cs 프로젝트: cheahengsoon/XamlCSS
 private static EventHandler RenderingHandler()
 {
     return((sender, e) =>
     {
         instance?.ExecuteApplyStyles();
     });
 }
예제 #3
0
파일: Css.cs 프로젝트: KenneyChen/XamlCSS
 private static void StartUiTimer()
 {
     Device.StartTimer(TimeSpan.FromMilliseconds(5), () =>
     {
         instance?.ExecuteApplyStyles();
         return(initialized);
     });
 }
예제 #4
0
파일: Css.cs 프로젝트: mediabuff/XamlCSS
        static Css()
        {
            Initialize();

            CompositionTarget.Rendering += (sender, e) =>
            {
                instance.ExecuteApplyStyles();
            };
        }
예제 #5
0
 private static void StartUiTimer()
 {
     timer = new Timer(TimeSpan.FromMilliseconds(16), (state) =>
     {
         Device.BeginInvokeOnMainThread(() =>
         {
             instance.ExecuteApplyStyles();
         });
     }, null);
 }
예제 #6
0
파일: Css.cs 프로젝트: banshanju/XamlCSS
 private static void StartUiTimer()
 {
     uiTimer = new Timer(TimeSpan.FromMilliseconds(16), (state) =>
     {
         var tcs = new TaskCompletionSource <object>();
         Device.BeginInvokeOnMainThread(() =>
         {
             instance?.ExecuteApplyStyles();
             tcs.SetResult(0);
         });
         tcs.Task.Wait();
     }, null);
 }
예제 #7
0
        public static void Initialize(IDictionary <string, List <string> > cssNamespaceMapping = null)
        {
            if (initialized)
            {
                return;
            }

            initialized = true;

            cssNamespaceMapping = cssNamespaceMapping ?? DefaultCssNamespaceMapping;

            TypeHelpers.Initialze(cssNamespaceMapping);

            var defaultCssNamespace       = cssNamespaceMapping.Keys.First();
            var dispatcher                = Application.Current?.Dispatcher ?? Dispatcher.CurrentDispatcher;
            var dependencyPropertyService = new DependencyPropertyService();
            var visualTreeNodeWithLogicalFallbackProvider = new TreeNodeProvider(dependencyPropertyService);
            var markupExtensionParser = new MarkupExtensionParser();
            var cssTypeHelper         = new CssTypeHelper <DependencyObject, DependencyProperty, Style>(markupExtensionParser, dependencyPropertyService);

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


            // mix CompositionTarget.Rendering and DispatcherTimer for better UI responsiveness
            CompositionTarget.Rendering += RenderingHandler;

            timer          = new DispatcherTimer(DispatcherPriority.Render);
            timer.Interval = TimeSpan.FromMilliseconds(5);
            timer.Tick    += (s, e) =>
            {
                instance?.ExecuteApplyStyles();
            };
            timer.Start();

            // Warmup(markupExtensionParser, defaultCssNamespace);
            //Warm();

            LoadedDetectionHelper.Initialize();
        }
예제 #8
0
        static Css()
        {
            Initialize();

            CompositionTarget.Rendering += (sender, e) =>
            {
                var evt = e as RenderingEventArgs;
                if (evt.RenderingTime == _lastRendering)
                {
                    return;
                }

                _lastRendering = evt.RenderingTime;

                instance.ExecuteApplyStyles();
            };
        }
예제 #9
0
        private static void Warmup(MarkupExtensionParser markupExtensionParser, string defaultCssNamespace)
        {
            // warmup parser
            markupExtensionParser.Parse("true", Application.Current?.MainWindow ?? new FrameworkElement(), new[] { new CssNamespace("", defaultCssNamespace) });

            TypeHelpers.GetPropertyAccessor(typeof(FrameworkElement), "IsLoaded");

            var styleSheet = CssParser.Parse("*{Background: #DynamicResource no;}");

            var f = new Button();

            f.SetValue(Css.StyleSheetProperty, styleSheet);
            f.Content = new TextBlock();

            instance.EnqueueNewElement(f, styleSheet, f);
            instance.ExecuteApplyStyles();
        }
예제 #10
0
        public static void Initialize()
        {
            if (initialized)
            {
                return;
            }

            LoadedDetectionHelper.Initialize();

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

            CompositionTarget.Rendering += (sender, e) =>
            {
                instance.ExecuteApplyStyles();
            };

            initialized = true;
        }
예제 #11
0
파일: Css.cs 프로젝트: Taikatou/XamlCSS
        public static void Initialize()
        {
            if (initialized)
            {
                return;
            }

            LoadedDetectionHelper.Initialize();

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

            dispatcherTimer          = new DispatcherTimer();
            dispatcherTimer.Interval = TimeSpan.FromMilliseconds(16);
            dispatcherTimer.Tick    += (s, e) =>
            {
                Initialize();
                instance.ExecuteApplyStyles();
            };
            dispatcherTimer.Start();

            initialized = true;
        }
예제 #12
0
파일: Css.cs 프로젝트: banshanju/XamlCSS
 private static void RenderingHandler(object sender, object e)
 {
     instance?.ExecuteApplyStyles();
 }
예제 #13
0
파일: Css.cs 프로젝트: KenneyChen/XamlCSS
        public static void Initialize(Element rootElement, Assembly[] resourceSearchAssemblies = null, IDictionary <string, List <string> > cssNamespaceMapping = null)
        {
            lock (lockObject)
            {
                if (initialized &&
                    rootElement == Css.rootElement)
                {
                    return;
                }

                Reset();

                initialized = true;

                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;

                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.MainPage != null)
                            {
                                application.PropertyChanged -= handler;
                                instance?.ExecuteApplyStyles();
                            }
                        };

                        application.PropertyChanged += handler;
                    }
                }

                StartUiTimer();
            }
        }