System.Windows.Markup.XamlReader.Load C# (CSharp) Method

Load() public static method

public static Load ( string xaml ) : object
xaml string
return object
		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 = XamlLoader.CreateManagedXamlLoader (Deployment.Current.EntryAssembly, null, Deployment.Current.Surface.Native, PluginHost.Handle);
			
			return loader.CreateObjectFromString (xaml, true);
		}

Usage Example

Example #1
0
        private async Task DownloadFileAsync2(Uri uri, string name)
        {
            try
            {
                var file = Path.Combine(Dispatcher.Invoke(() => TempPath), name);

                if (File.Exists(file))
                    File.Delete(file);

                using (var webClient = new WebClient { Credentials = CredentialCache.DefaultNetworkCredentials })
                    await webClient.DownloadFileTaskAsync(uri, file);

                //Saves the template for later, when exporting the translation.
                if (name.EndsWith("en.xaml"))
                    _resourceTemplate = File.ReadAllText(file);

                using (var fs = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    var dictionary = (ResourceDictionary)XamlReader.Load(fs, new ParserContext { XmlSpace = "preserve" });
                    //var dictionary = new ResourceDictionary();
                    dictionary.Source = new Uri(Path.GetFullPath(file), UriKind.Absolute);

                    _resourceList.Add(dictionary);

                    if (name.EndsWith("en.xaml"))
                        Application.Current.Resources.MergedDictionaries.Add(dictionary);
                }
            }
            catch (Exception ex)
            {
                Dispatcher.Invoke(() => Dialog.Ok("Translator", "Translator - Downloading File", ex.Message));
            }
        }
All Usage Examples Of System.Windows.Markup.XamlReader::Load