Exemplo n.º 1
0
        /// <summary>
        /// Reads page item from Xml element and adds it as a child to the parent.
        /// </summary>
        /// <param name="parent"></param>
        /// <param name="categoryNode"></param>
        private void _AddPageItem(CategoryItem parent, XmlElement categoryNode)
        {
            PageItem newPage = new PageItem();

            string typeName = categoryNode.GetAttribute(XML_TYPE_ATTRIBUTE_NAME, "");

            newPage.PageType = Type.GetType(typeName);

            // page type should exist
            Debug.Assert(newPage.PageType != null);

            // add new page to the parent
            newPage.Parent = parent;
            parent.AddChild(newPage);
        }
        /// <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);
            }
        }
        /// <summary>
        /// Sets binding to all necessary properties.
        /// </summary>
        /// <param name="navPage"></param>
        /// <param name="item"></param>
        private void _SetPropertiesBinding(NavigationPanePage navPage, PageItem item)
        {
            Binding enablingBinding = new Binding("IsAllowed");
            enablingBinding.Mode = BindingMode.OneWay;
            enablingBinding.Source = item.Page;
            enablingBinding.NotifyOnSourceUpdated = true;
            BindingOperations.SetBinding(navPage, NavigationPanePage.IsEnabledProperty, enablingBinding);

            Binding reuquiredBinding = new Binding("IsRequired");
            reuquiredBinding.Mode = BindingMode.OneWay;
            reuquiredBinding.Source = item.Page;
            reuquiredBinding.NotifyOnSourceUpdated = true;
            BindingOperations.SetBinding(navPage, NavigationPanePage.IsPageRequiredProperty, reuquiredBinding);

            Binding canCompleteBinding = new Binding("DoesSupportCompleteStatus");
            canCompleteBinding.Mode = BindingMode.OneWay;
            canCompleteBinding.Source = item.Page;
            canCompleteBinding.NotifyOnSourceUpdated = true;
            BindingOperations.SetBinding(navPage, NavigationPanePage.DoesSupportCompleteStatusProperty, canCompleteBinding);

            Binding completeBinding = new Binding("IsComplete");
            completeBinding.Mode = BindingMode.OneWay;
            completeBinding.Source = item.Page;
            completeBinding.NotifyOnSourceUpdated = true;
            BindingOperations.SetBinding(navPage, NavigationPanePage.IsPageCompleteProperty, completeBinding);
        }
        /// <summary>
        /// Navigates to the specified page.
        /// </summary>
        /// <param name="item"></param>
        private void _Navigate(PageItem item)
        {
            // If this page cannot be left - do not navigate from current page.
            if ((_currentPage != item.Page) && !_currentPage.CanBeLeft)
                item = _currentPageItem;

            _NotifyNavigationCalled();

            this.RemoveHandler(NavigationPane.ChangeSelectionEvent, (RoutedEventHandler)OnCurrentPageChanged);

            CategoryItem currentCategory = (CategoryItem)item.Parent;

            if (item.Page.IsAllowed &&
                ((null == currentCategory.PageCategory) || // NOTE: category can be not belong to categories ("Preferences")
                ((null != currentCategory.PageCategory) && currentCategory.PageCategory.IsEnabled)))
            {
                PageFrame.Navigate(item.Page);

                _ChangeCurrentCategory(item.Parent as INavigationItem);
                _UpdateCurrentCategoryButton();

                // Add widgets panel to hash table
                if (!_widgetsHash.Contains(item.PageType.FullName))
                {
                    StackPanel widgetsStack = _CreateWidgetsPanel(item.Page);
                    _widgetsHash.Add(item.PageType.FullName, widgetsStack);
                }

                foreach (NavigationPanePage panePage in navigationPane.Pages)
                {
                    if (panePage.Tag == item)
                    {   // set navigation pane content
                        panePage.PageContent = (StackPanel)_widgetsHash[item.PageType.FullName];
                        navigationPane.SelectPage(panePage);
                        break;
                    }
                }
                _taskPanelContentBuilder.UpdateTaskPanelWidgetsState((StackPanel)_widgetsHash[item.PageType.FullName]);
                _currentPageItem = item;
                _currentPage = item.Page;
            }

            this.AddHandler(NavigationPane.ChangeSelectionEvent, new RoutedEventHandler(OnCurrentPageChanged));
        }
Exemplo n.º 5
0
        /// <summary>
        /// Reads page item from Xml element and adds it as a child to the parent.
        /// </summary>
        /// <param name="parent"></param>
        /// <param name="categoryNode"></param>
        private void _AddPageItem(CategoryItem parent, XmlElement categoryNode)
        {
            PageItem newPage = new PageItem();

            string typeName = categoryNode.GetAttribute(XML_TYPE_ATTRIBUTE_NAME, "");
            newPage.PageType = Type.GetType(typeName);

            // page type should exist
            Debug.Assert(newPage.PageType != null);

            // add new page to the parent
            newPage.Parent = parent;
            parent.AddChild(newPage);
        }