Load() public static method

public static Load ( string xaml ) : object
xaml string
return object
コード例 #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));
            }
        }
コード例 #2
0
        /// <summary>Reads the XAML markup in the specified text string (using a specified <see cref="T:System.Windows.Markup.ParserContext" />) and returns an object that corresponds to the root of the specified markup.</summary>
        /// <param name="xamlText">The input XAML, as a single text string.</param>
        /// <param name="parserContext">Context information used by the parser.</param>
        /// <returns>The root of the created object tree.</returns>
        // Token: 0x06002382 RID: 9090 RVA: 0x000AD6AC File Offset: 0x000AB8AC
        public static object Parse(string xamlText, ParserContext parserContext)
        {
            Stream stream = new MemoryStream(Encoding.Default.GetBytes(xamlText));

            return(XamlReader.Load(stream, parserContext));
        }