Exemplo n.º 1
0
        public static void LoadComponent(object component, Uri resourceLocator)
        {
            if (component == null)
            {
                throw new ArgumentNullException("component");
            }

            if (resourceLocator == null)
            {
                throw new ArgumentNullException("resourceLocator");
            }

            StreamResourceInfo sr = GetResourceStream(resourceLocator);

            if (sr == null)
            {
                // throws for case like a resource outside the XAP (e.g. DRT924) i.e. no assembly specified
                if (resourceLocator.ToString().IndexOf(';') == -1)
                {
                    throw new XamlParseException();
                }
                // otherwise simply return
                return;
            }

            Assembly loading_asm = component.GetType().Assembly;

            XamlLoader loader = XamlLoaderFactory.CreateLoader(loading_asm, resourceLocator, Deployment.Current.Surface.Native, PluginHost.Handle);

            loader.Hydrate(component, sr.Stream);
        }
Exemplo n.º 2
0
        internal Style GetGenericXamlStyleFor(Type type)
        {
            ResourceDictionary rd = null;

            if (assemblyToGenericXaml.ContainsKey(type.Assembly))
            {
                rd = assemblyToGenericXaml[type.Assembly];
            }
            else
            {
                Console.WriteLine("trying to load: /{0};component/themes/generic.xaml",
                                  type.Assembly.GetName().Name);

                StreamResourceInfo info = null;

                try {
                    info = GetResourceStream(new Uri(string.Format("/{0};component/themes/generic.xaml",
                                                                   type.Assembly.GetName().Name), UriKind.Relative));
                }
                catch {
                    Console.WriteLine("no generic.xaml for assembly {0}", type.Assembly.GetName().Name);
                }

                if (info != null)
                {
                    using (StreamReader sr = new StreamReader(info.Stream)) {
                        Uri        resource_base = UriHelper.FromNativeUri(NativeMethods.dependency_object_get_resource_base(NativeHandle));
                        XamlLoader loader        = XamlLoaderFactory.CreateLoader(type.Assembly, resource_base, Deployment.Current.Surface.Native, PluginHost.Handle);

                        try {
                            rd = loader.CreateObjectFromReader(sr, false) as ResourceDictionary;
                        }
                        catch (Exception e) {
                            Console.WriteLine("failed generic.xaml parsing:");
                            Console.WriteLine(e);
                        }
                    }
                }

                if (rd == null)
                {
                    // create an empty one so we don't fall into this block again for this assembly
                    rd = new ResourceDictionary();
                }

                assemblyToGenericXaml[type.Assembly] = rd;
            }

            if (Deployment.Current.MajorVersion < 4)
            {
                return(rd[type.FullName] as Style);
            }
            else
            {
                return(rd[type] as Style);
            }
        }
Exemplo n.º 3
0
        public static object Load(string xaml)
        {
            // if 'xaml' is null then this will throw a NullReferenceException, just like SL2 throws for null
            if (xaml.Length == 0)
            {
                return(null);
            }

            XamlLoader loader = XamlLoaderFactory.CreateLoader();

            return(loader.CreateObjectFromString(xaml, true));
        }
Exemplo n.º 4
0
        void ReadManifest()
        {
            XamlLoader loader       = XamlLoaderFactory.CreateLoader(typeof(DependencyObject).Assembly, null, Surface.Native, PluginHost.Handle);
            string     app_manifest = Path.Combine(XapDir, "appmanifest.xaml");

            if (!File.Exists(app_manifest))
            {
                throw new MoonException(2103, "Invalid or malformed application: Check manifest");
            }

            Stream app_manifest_stream = null;

            try {
                app_manifest_stream = File.OpenRead(app_manifest);
                loader.Hydrate(this, app_manifest_stream);
            } catch (Exception e) {
                throw new MoonException(7016, e.Message);
            } finally {
                if (app_manifest_stream != null)
                {
                    app_manifest_stream.Close();
                }
            }

            if (RuntimeVersion == null)
            {
                throw new MoonException(2105, "No RuntimeVersion specified in AppManifest");
            }

            CompareRuntimeVersions();

            if (EntryPointAssembly == null)
            {
                throw new MoonException(2103, "Invalid or malformed application: Check manifest");
            }

            if (EntryPointType == null)
            {
                throw new Exception("No entrypoint defined in the AppManifest.xaml");
            }
        }
Exemplo n.º 5
0
        public static object LoadWithInitialTemplateValidation(string xaml)
        {
            XamlLoader loader = XamlLoaderFactory.CreateLoader();

            return(loader.CreateObjectFromString(xaml, true, true));
        }