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(); }
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; }
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; } }