示例#1
0
        /// <summary>
        /// Gets and returns the current UWP XAML Application instance in a reference parameter.
        /// If the current XAML Application instance has not been created for the process (is null),
        /// a new <see cref="Microsoft.Toolkit.Win32.UI.XamlHost.XamlApplication" /> instance is created and returned.
        /// </summary>
        /// <returns>The instance of <seealso cref="XamlApplication"/></returns>
        public static IXamlMetadataContainer GetOrCreateXamlMetadataContainer()
        {
            // Instantiation of the application object must occur before creating the DesktopWindowXamlSource instance.
            // DesktopWindowXamlSource will create a generic Application object unable to load custom UWP XAML metadata.
            if (_metadataContainer == null)
            {
                // Create a custom UWP XAML Application object that implements reflection-based XAML metadata probing.
                try
                {
                    var app = new XamlApplication();
                    app.MetadataProviders.AddRange(MetadataProviderDiscovery.DiscoverMetadataProviders());
                    return(app);
                }
                catch
                {
                    _metadataContainer = WUX.Application.Current as IXamlMetadataContainer;
                }
            }

            var xamlApplication = _metadataContainer as XamlApplication;

            if (xamlApplication != null && xamlApplication.IsDisposed)
            {
                throw new ObjectDisposedException(typeof(XamlApplication).FullName);
            }

            return(_metadataContainer);
        }
示例#2
0
 /// <summary>
 /// Probes file system for UWP XAML metadata providers
 /// </summary>
 private void EnsureMetadataProviders()
 {
     if (_metadataProviders == null)
     {
         _metadataProviders = MetadataProviderDiscovery.DiscoverMetadataProviders(FilteredTypes);
     }
 }
示例#3
0
 /// <summary>
 /// Probes file system for UWP XAML metadata providers
 /// </summary>
 private void EnsureMetadataProviders()
 {
     if (_metadataProviders == null)
     {
         _metadataProviders = MetadataProviderDiscovery.DiscoverMetadataProviders(new List <Type> {
             typeof(XamlApplication)
         });
     }
 }
示例#4
0
        /// <summary>
        /// Gets and returns the current UWP XAML Application instance in a reference parameter.
        /// If the current XAML Application instance has not been created for the process (is null),
        /// a new <see cref="Microsoft.Toolkit.Win32.UI.XamlHost.XamlApplication" /> instance is created and returned.
        /// </summary>
        /// <returns>The instance of <seealso cref="XamlApplication"/></returns>
        public static IXamlMetadataContainer GetOrCreateXamlMetadataContainer()
        {
            // Instantiation of the application object must occur before creating the DesktopWindowXamlSource instance.
            // DesktopWindowXamlSource will create a generic Application object unable to load custom UWP XAML metadata.
            if (_metadataContainer == null && !_initialized)
            {
                _initialized = true;

                // Create a custom UWP XAML Application object that implements reflection-based XAML metadata probing.
                try
                {
                    _metadataContainer = GetCurrentProvider();
                    if (_metadataContainer == null)
                    {
                        var providers = MetadataProviderDiscovery.DiscoverMetadataProviders().ToList();
                        _metadataContainer = GetCurrentProvider();
                        if (_metadataContainer == null)
                        {
                            _metadataContainer = new XamlApplication(providers);
                            return(_metadataContainer);
                        }
                    }
                    else
                    {
                        return(_metadataContainer);
                    }
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine(ex.ToString());
                    _metadataContainer = GetCurrentProvider();
                }
            }

            var xamlApplication = _metadataContainer as XamlApplication;

            if (xamlApplication != null && xamlApplication.IsDisposed)
            {
                throw new ObjectDisposedException(typeof(XamlApplication).FullName);
            }

            return(_metadataContainer);
        }