Rediscovering the Obvious

…stumbling in the footsteps of greatness

Pack Notation for style merging

without comments

Just so I remember (Company.Product.Module is the naming convention we use for both namespaces and assemblies)  

            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source=”pack://application:,,,/Company.Product.Module;component/AppStyles.xaml”/>
            </ResourceDictionary.MergedDictionaries>

[EDIT]
The code for loading this into the application resources during startup is:

        // In App : Application
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);

            Uri uri = new Uri(“pack://application:,,,/Company.Product.Module;component/AppStyles.xaml”);
            ResourceDictionary rd = new ResourceDictionary();
            rd.Source = uri;
            Application.Current.Resources.MergedDictionaries.Add(rd);
        }

 

If you wish to use Application.Current.LoadComponent( uri ), however, it fails with an error that absolute URI’s are not allowed.  This pack:// naming convention was a bear to figure out the details, and several of the examples provide by the MSDN text do not work.

More information on the pack notation in WPF at http://msdn2.microsoft.com/en-us/library/aa970069.aspx

[UPDATE2]

http://nerddawg.blogspot.com/2005/12/more-on-resource-loading-in-wpf.html has a lot more information on this.
 

Written by erwilleke

April 3rd, 2007 at 4:06 pm

Posted in Uncategorized

Leave a Reply