示例#1
0
文件: Application.cs 项目: shana/moon
		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);

			// Does not seem to throw.
			if (sr == null)
				return;

			using (var v = Value.FromObject (component)) {
				// XXX still needed for the app.surface reference when creating the ManagedXamlLoader
				// Application app = component as Application;
	
				string xaml = new StreamReader (sr.Stream).ReadToEnd ();
				Assembly loading_asm = component.GetType ().Assembly;
	
				ManagedXamlLoader loader = new ManagedXamlLoader (loading_asm, resourceLocator.ToString(), Deployment.Current.Surface.Native, PluginHost.Handle);
				loader.Hydrate (v, xaml);
			}
		}
示例#2
0
文件: Application.cs 项目: shana/moon
		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)) {
						string generic_xaml = sr.ReadToEnd();
						string resource_base = NativeMethods.dependency_object_get_resource_base (NativeHandle);
						ManagedXamlLoader loader = new ManagedXamlLoader (type.Assembly, resource_base, Deployment.Current.Surface.Native, PluginHost.Handle);

						try {
							rd = loader.CreateObjectFromString (generic_xaml, 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;
			}

			return rd[type.FullName] as Style;
		}