コード例 #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>
 /// 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>
 internal static void GetOrCreateXamlApplicationInstance(ref Windows.UI.Xaml.Application application)
 {
     // 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 (application == null)
     {
         try
         {
             // Windows.UI.Xaml.Application.Current may throw if DXamlCore has not been initialized.
             // Treat the exception as an uninitialized Windows.UI.Xaml.Application condition.
             application = Windows.UI.Xaml.Application.Current;
         }
         catch
         {
             // Create a custom UWP XAML Application object that implements reflection-based XAML metadata probing.
             application = new XamlApplication();
         }
     }
 }
コード例 #3
0
 private static void RaiseApplicationCreated(XamlApplication application)
 {
     ApplicationCreated?.Invoke(application, new EventArgs());
 }