コード例 #1
0
        /// <summary>
        /// Add custom page to category
        /// </summary>
        private void _AddCustomPage(Assembly pluginAssembly, Type pluginType, INavigationItem category)
        {
            try
            {
                PageItem newPage = new PageItem();
                newPage.PageType = pluginAssembly.GetType(pluginType.ToString());
                newPage.Page = (AppPages.Page)Activator.CreateInstance(newPage.PageType);
                newPage.Page.Initialize(App.Current);

                INavigationItem foundItem = null;
                if (category.FindItem(newPage.Page.Name, out foundItem))
                {   // not unique page - add warning
                    string messageFormat = (string)App.Current.FindResource("UnableLoadNotUniqueCustomPage");
                    string path = string.Format(FULL_PAGE_NAME_FORMAT, category.Name, newPage.Page.Name);
                    string message = string.Format(messageFormat, path, Path.GetFileName(pluginAssembly.Location));
                    App.Current.Messenger.AddWarning(message);
                }
                else
                {   // add new page to the parent
                    newPage.Parent = category;
                    category.AddChild(newPage);
                }
            }
            catch (Exception e)
            {
                Logger.Error(e);
            }
        }