private static XamlNamespaceRegistry CreateXamlNamespaceRegistry() { var xamlNamespaceRegistry = new XamlNamespaceRegistry(); var forcedAssemblies = new[] { typeof (Control), typeof(Style) }.Select(t => t.GetTypeInfo().Assembly); foreach (var nsa in forcedAssemblies .Concat(PerspexLocator.Current.GetService<IPclPlatformWrapper>().GetLoadedAssemblies()) .Distinct() .SelectMany(asm => asm.GetCustomAttributes<XmlnsDefinitionAttribute>().Select(attr => new {asm, attr})) .GroupBy(entry => entry.attr.XmlNamespace)) { var def = XamlNamespace.Map(nsa.Key) .With(nsa.GroupBy(x => x.asm).Select( a => Route.Assembly(a.Key) .WithNamespaces(a.Select(entry => entry.attr.ClrNamespace).ToList()) )); xamlNamespaceRegistry.AddNamespace(def); } xamlNamespaceRegistry.RegisterPrefix(new PrefixRegistration(string.Empty, PerspexNs)); return xamlNamespaceRegistry; }
private static XamlNamespaceRegistry CreateXamlNamespaceRegistry() { var xamlNamespaceRegistry = new XamlNamespaceRegistry(); var rootType = typeof(Control); var bindingType = typeof(BindingExtension); var templateType = typeof(XamlDataTemplate); var definitionForRoot = XamlNamespace .Map(PerspexNs) .With( new[] { Route.Assembly(rootType.GetTypeInfo().Assembly).WithNamespaces( new[] { rootType.Namespace }), Route.Assembly(bindingType.GetTypeInfo().Assembly).WithNamespaces( new[] { bindingType.Namespace, }), Route.Assembly(templateType.GetTypeInfo().Assembly).WithNamespaces( new[] { templateType.Namespace, }) }); foreach (var ns in new List<XamlNamespace> { definitionForRoot }) { xamlNamespaceRegistry.AddNamespace(ns); } xamlNamespaceRegistry.RegisterPrefix(new PrefixRegistration(string.Empty, PerspexNs)); return xamlNamespaceRegistry; }