private static void RenderingHandler(object sender, EventArgs e) { if (instance?.ExecuteApplyStyles() == true) { // after the first successful applying remove the handler. CompositionTarget.Rendering -= RenderingHandler; } }
private static EventHandler RenderingHandler() { return((sender, e) => { instance?.ExecuteApplyStyles(); }); }
private static void StartUiTimer() { Device.StartTimer(TimeSpan.FromMilliseconds(5), () => { instance?.ExecuteApplyStyles(); return(initialized); }); }
static Css() { Initialize(); CompositionTarget.Rendering += (sender, e) => { instance.ExecuteApplyStyles(); }; }
private static void StartUiTimer() { timer = new Timer(TimeSpan.FromMilliseconds(16), (state) => { Device.BeginInvokeOnMainThread(() => { instance.ExecuteApplyStyles(); }); }, null); }
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); }
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(); }
static Css() { Initialize(); CompositionTarget.Rendering += (sender, e) => { var evt = e as RenderingEventArgs; if (evt.RenderingTime == _lastRendering) { return; } _lastRendering = evt.RenderingTime; instance.ExecuteApplyStyles(); }; }
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(); }
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; }
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; }
private static void RenderingHandler(object sender, object e) { instance?.ExecuteApplyStyles(); }
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(); } }