コード例 #1
0
 private void LoadThemeResourceFromFile(Uri resorceUri)
 {
     //TODO: Implement external theme loading
     try
     {
         StreamResourceInfo info = Application.GetRemoteStream(resorceUri);
         System.Windows.Markup.XamlReader reader = new System.Windows.Markup.XamlReader();
         ResourceDictionary resource             = (ResourceDictionary)reader.LoadAsync(info.Stream);
         AppearanceManager.Current.AddTheme(resource, true);
     }
     catch (IOException)
     {
         // do something
     }
 }
コード例 #2
0
ファイル: Manager.cs プロジェクト: powercode/seeshell
        public static void LoadApplicationResources()
        {
            Uri uri = new Uri("pack://application:,,,/CodeOwls.SeeShell.Visualizations;component/DataTemplates.xaml");

            try
            {
                var info = Application.GetResourceStream(uri);
                var reader = new XamlReader();

                var resources = (ResourceDictionary) reader.LoadAsync(info.Stream);

                Application.Current.Resources.MergedDictionaries.Add(resources);
            }
            catch
            {
            }
        }
コード例 #3
0
ファイル: XamlReader.cs プロジェクト: dox0/DotNet471RS3
        /// <summary>
        /// Reads XAML from the passed stream, building an object tree and returning the
        /// root of that tree.  Wrap a CompatibilityReader with another XmlReader that
        /// uses the passed reader settings to allow validation of xaml.
        /// </summary>
        /// <param name="reader">XmlReader to use.  This is NOT wrapped by any
        ///  other reader</param>
        /// <param name="context">Optional parser context.  May be null </param>
        /// <param name="parseMode">Sets synchronous or asynchronous parsing</param>
        /// <returns>object root generated after xml parsed</returns>
        // Note this is the internal entry point for XPS.  XPS calls here so
        // its reader is not wrapped with a Markup Compat Reader.
        internal static object Load(
            XmlReader reader,
            ParserContext parserContext,
            XamlParseMode parseMode)
        {
            if (parseMode == XamlParseMode.Uninitialized ||
                parseMode == XamlParseMode.Asynchronous)
            {
                XamlReader xamlReader = new XamlReader();
                return(xamlReader.LoadAsync(reader, parserContext));
            }

            if (parserContext == null)
            {
                parserContext = new ParserContext();
            }

#if DEBUG_CLR_MEM
            bool clrTracingEnabled = false;
            // Use local pass variable to correctly log nested parses.
            int pass = 0;

            if (CLRProfilerControl.ProcessIsUnderCLRProfiler &&
                (CLRProfilerControl.CLRLoggingLevel >= CLRProfilerControl.CLRLogState.Performance))
            {
                clrTracingEnabled = true;
                pass = ++_CLRXamlPass;
                CLRProfilerControl.CLRLogWriteLine("Begin_XamlParse_{0}", pass);
            }
#endif // DEBUG_CLR_MEM

            EventTrace.EasyTraceEvent(EventTrace.Keyword.KeywordXamlBaml, EventTrace.Event.WClientParseXmlBegin, parserContext.BaseUri);

            if (TraceMarkup.IsEnabled)
            {
                TraceMarkup.Trace(TraceEventType.Start, TraceMarkup.Load);
            }
            object root = null;
            try
            {
                if (parserContext.BaseUri == null ||
                    String.IsNullOrEmpty(parserContext.BaseUri.ToString()))
                {
                    if (reader.BaseURI == null ||
                        String.IsNullOrEmpty(reader.BaseURI.ToString()))
                    {
                        parserContext.BaseUri = BaseUriHelper.PackAppBaseUri;
                    }
                    else
                    {
                        parserContext.BaseUri = new Uri(reader.BaseURI);
                    }
                }

                System.Xaml.XamlXmlReaderSettings settings = new System.Xaml.XamlXmlReaderSettings();
                settings.IgnoreUidsOnPropertyElements = true;
                settings.BaseUri         = parserContext.BaseUri;
                settings.ProvideLineInfo = true;

                XamlSchemaContext schemaContext = parserContext.XamlTypeMapper != null ?
                                                  parserContext.XamlTypeMapper.SchemaContext : GetWpfSchemaContext();
                System.Xaml.XamlXmlReader xamlXmlReader = new System.Xaml.XamlXmlReader(reader, schemaContext, settings);
                root = Load(xamlXmlReader, parserContext);
                reader.Close();
            }
            catch (Exception e)
            {
                // Don't wrap critical exceptions or already-wrapped exceptions.
                if (MS.Internal.CriticalExceptions.IsCriticalException(e) || !ShouldReWrapException(e, parserContext.BaseUri))
                {
                    throw;
                }
                RewrapException(e, parserContext.BaseUri);
            }
            finally
            {
                if (TraceMarkup.IsEnabled)
                {
                    TraceMarkup.Trace(TraceEventType.Stop, TraceMarkup.Load, root);
                }

                EventTrace.EasyTraceEvent(EventTrace.Keyword.KeywordXamlBaml, EventTrace.Event.WClientParseXmlEnd, parserContext.BaseUri);

#if DEBUG_CLR_MEM
                if (clrTracingEnabled && (CLRProfilerControl.CLRLoggingLevel >= CLRProfilerControl.CLRLogState.Performance))
                {
                    CLRProfilerControl.CLRLogWriteLine("End_XamlParse_{0}", pass);
                }
#endif // DEBUG_CLR_MEM
            }
            return(root);
        }
コード例 #4
0
        internal static object XamlConverter(Stream stream, Uri baseUri, bool canUseTopLevelBrowser, bool sandboxExternalContent, bool allowAsync, bool isJournalNavigation, out XamlReader asyncObjectConverter)
        { 
            asyncObjectConverter = null;

            if (sandboxExternalContent)
            { 
                if (SecurityHelper.AreStringTypesEqual(baseUri.Scheme, BaseUriHelper.PackAppBaseUri.Scheme))
                { 
                    baseUri = BaseUriHelper.ConvertPackUriToAbsoluteExternallyVisibleUri(baseUri); 
                }
 
                stream.Close();

                WebBrowser webBrowser = new WebBrowser();
                webBrowser.Source = baseUri; 
                return webBrowser;
            } 
            else 
            {
                ParserContext pc = new ParserContext(); 

                pc.BaseUri = baseUri;
                pc.SkipJournaledProperties = isJournalNavigation;
 
                if (allowAsync)
                { 
                    XamlReader xr = new XamlReader(); 
                    asyncObjectConverter = xr;
                    xr.LoadCompleted += new AsyncCompletedEventHandler(OnParserComplete); 
                    // XamlReader.Load will close the stream.
                    return xr.LoadAsync(stream, pc);
                }
                else 
                {
                    // XamlReader.Load will close the stream. 
                    return XamlReader.Load(stream, pc); 
                }
            } 
        }
コード例 #5
0
ファイル: XamlReader.cs プロジェクト: sjyanxin/WPFSource
        /// <summary> 
        /// Reads XAML from the passed stream, building an object tree and returning the
        /// root of that tree.  Wrap a CompatibilityReader with another XmlReader that 
        /// uses the passed reader settings to allow validation of xaml.
        /// </summary>
        /// <param name="reader">XmlReader to use.  This is NOT wrapped by any
        ///  other reader</param> 
        /// <param name="context">Optional parser context.  May be null </param>
        /// <param name="parseMode">Sets synchronous or asynchronous parsing</param> 
        /// <returns>object root generated after xml parsed</returns> 
        // Note this is the internal entry point for XPS.  XPS calls here so
        // its reader is not wrapped with a Markup Compat Reader. 
        internal static object Load(
            XmlReader reader,
            ParserContext parserContext,
            XamlParseMode parseMode) 
        {
            if (parseMode == XamlParseMode.Uninitialized || 
                parseMode == XamlParseMode.Asynchronous) 
            {
                XamlReader xamlReader = new XamlReader(); 
                return xamlReader.LoadAsync(reader, parserContext);
            }

            if (parserContext == null) 
            {
                parserContext = new ParserContext(); 
            } 

#if DEBUG_CLR_MEM 
            bool clrTracingEnabled = false;
            // Use local pass variable to correctly log nested parses.
            int pass = 0;
 
            if (CLRProfilerControl.ProcessIsUnderCLRProfiler &&
               (CLRProfilerControl.CLRLoggingLevel >= CLRProfilerControl.CLRLogState.Performance)) 
            { 
                clrTracingEnabled = true;
                pass = ++_CLRXamlPass; 
                CLRProfilerControl.CLRLogWriteLine("Begin_XamlParse_{0}", pass);
            }
#endif // DEBUG_CLR_MEM
 
            EventTrace.EasyTraceEvent(EventTrace.Keyword.KeywordXamlBaml, EventTrace.Event.WClientParseXmlBegin, parserContext.BaseUri);
 
            if (TraceMarkup.IsEnabled) 
            {
                TraceMarkup.Trace(TraceEventType.Start, TraceMarkup.Load); 
            }
            object root = null;
            try
            { 

                if (parserContext.BaseUri == null || 
                    String.IsNullOrEmpty(parserContext.BaseUri.ToString())) 
                {
                    if (reader.BaseURI == null || 
                        String.IsNullOrEmpty(reader.BaseURI.ToString()))
                    {
                        parserContext.BaseUri = BaseUriHelper.PackAppBaseUri;
                    } 
                    else
                    { 
                        parserContext.BaseUri = new Uri(reader.BaseURI); 
                    }
                } 

                System.Xaml.XamlXmlReaderSettings settings = new System.Xaml.XamlXmlReaderSettings();
                settings.IgnoreUidsOnPropertyElements = true;
                settings.BaseUri = parserContext.BaseUri; 
                settings.ProvideLineInfo = true;
 
                XamlSchemaContext schemaContext = parserContext.XamlTypeMapper != null ? 
                    parserContext.XamlTypeMapper.SchemaContext : GetWpfSchemaContext();
                System.Xaml.XamlXmlReader xamlXmlReader = new System.Xaml.XamlXmlReader(reader, schemaContext, settings); 
                root = Load(xamlXmlReader, parserContext);
                reader.Close();
            }
            catch (Exception e) 
            {
                // Don't wrap critical exceptions or already-wrapped exceptions. 
                if(MS.Internal.CriticalExceptions.IsCriticalException(e) || !ShouldReWrapException(e, parserContext.BaseUri)) 
                {
                    throw; 
                }
                RewrapException(e, parserContext.BaseUri);
            }
            finally 
            {
                if (TraceMarkup.IsEnabled) 
                { 
                    TraceMarkup.Trace(TraceEventType.Stop, TraceMarkup.Load, root);
                } 

                EventTrace.EasyTraceEvent(EventTrace.Keyword.KeywordXamlBaml, EventTrace.Event.WClientParseXmlEnd, parserContext.BaseUri);

#if DEBUG_CLR_MEM 
                if (clrTracingEnabled && (CLRProfilerControl.CLRLoggingLevel >= CLRProfilerControl.CLRLogState.Performance))
                { 
                    CLRProfilerControl.CLRLogWriteLine("End_XamlParse_{0}", pass); 
                }
#endif // DEBUG_CLR_MEM 
            }
            return root;
        }