コード例 #1
0
        /// <summary>
        /// An element in the Settings Tree is selected, now do:
        /// 1) if a SettingsPage is registered to the item:
        /// a) Create the page if it wasn't created
        /// b) Show the page
        /// 2) if a URL is registered to the item, navigate to it
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void TreeView_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs <object> e)
        {
            SettingsTreeItem settingsTreeItem = (SettingsTreeItem)e.NewValue;

            if (settingsTreeItem != null)
            {
                if (settingsTreeItem.SettingsPage != null)
                {
                    CurrentSettingsPage.Content = settingsTreeItem.SettingsPage;
                }
                else if (settingsTreeItem.SettingsPageType != null)
                {
                    settingsTreeItem.SettingsPage = InstanciatePage(settingsTreeItem.SettingsPageType);
                    CurrentSettingsPage.Content   = settingsTreeItem.SettingsPage;
                }
                else if (settingsTreeItem.Url != null)
                {
                    CurrentSettingsPage.Navigate(new Uri(settingsTreeItem.Url));
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Register the SettingsPage Type T or URL to the supplied the keyPath
        /// </summary>
        /// <param name="settingsPageType">Type which extends SettingsPage</param>
        /// <param name="keyPath">key,key,key</param>
        /// <param name="url">URL for the path</param>
        public static void RegisterSettingsPage(string keyPath, Type settingsPageType, string url)
        {
            IDictionary <string, SettingsTreeItem> current = treeItems;

            string[] pathEntries     = keyPath.Split(new char[] { ',' });
            string   currentLocation = null;

            for (int i = 0; i < pathEntries.Length; i++)
            {
                currentLocation = pathEntries[i];
                if (current.ContainsKey(currentLocation))
                {
                    if (i == pathEntries.Length - 1)
                    {
                        current[currentLocation].SettingsPageType = settingsPageType;
                        current[currentLocation].Url = url;
                    }
                    current = current[currentLocation].Children;
                }
                else if (i < pathEntries.Length - 1)
                {
                    SettingsTreeItem item = new SettingsTreeItem {
                        Key = currentLocation
                    };
                    current.Add(currentLocation, item);
                    current = item.Children;
                }
                else
                {
                    current.Add(currentLocation, new SettingsTreeItem {
                        Key = currentLocation,
                        SettingsPageType = settingsPageType,
                        Url = url
                    });
                }
            }
        }