118 lines · 4.2 KB · C#
RawDownload
//******************************************************************************************************//  HomeUserControl.xaml.cs - Gbtc////  Copyright © 2010, Grid Protection Alliance.  All Rights Reserved.////  Licensed to the Grid Protection Alliance (GPA) under one or more contributor license agreements. See//  the NOTICE file distributed with this work for additional information regarding copyright ownership.//  The GPA licenses this file to you under the MIT License (MIT), the "License"; you may//  not use this file except in compliance with the License. You may obtain a copy of the License at:////      http://www.opensource.org/licenses/MIT////  Unless agreed to in writing, the subject software distributed under the License is distributed on an//  "AS-IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Refer to the//  License for the specific language governing permissions and limitations.////  Code Modification History://  ----------------------------------------------------------------------------------------------------//  07/27/2011 - Mehulbhai P Thakkar//       Generated original version of source code.////****************************************************************************************************** using System.Collections.ObjectModel;using System.Windows;using System.Windows.Controls;using System.Xml;using System.Xml.Serialization;using GSF.IO; namespace GSF.TimeSeries.UI.UserControls{    /// <summary>    /// Interaction logic for HomeUserControl.xaml    /// </summary>    public partial class HomeUserControl : UserControl    {        #region [ Members ]         // Fields        private readonly ObservableCollection<MenuDataItem> m_menuDataItems;         #endregion         #region [ Constructors ]         /// <summary>        /// Creates an instance of <see cref="HomeUserControl"/>.        /// </summary>        public HomeUserControl()        {            InitializeComponent();            // Load Menu            XmlRootAttribute xmlRootAttribute = new XmlRootAttribute("MenuDataItems");            XmlSerializer serializer = new XmlSerializer(typeof(ObservableCollection<MenuDataItem>), xmlRootAttribute);             using (XmlReader reader = XmlReader.Create(FilePath.GetAbsolutePath("Menu.xml")))            {                m_menuDataItems = (ObservableCollection<MenuDataItem>)serializer.Deserialize(reader);            }        }         #endregion         #region [ Methods ]         /// <summary>        /// Recursively finds menu item to navigate to when a button is clicked on the UI.        /// </summary>        /// <param name="items">Collection of menu items.</param>        /// <param name="stringToMatch">Item to search for in menu items collection.</param>        /// <param name="item">Returns a menu item.</param>        private void GetMenuDataItem(ObservableCollection<MenuDataItem> items, string stringToMatch, ref MenuDataItem item)        {            for (int i = 0; i < items.Count; i++)            {                if (items[i].MenuText.Contains(stringToMatch))                {                    item = items[i];                    break;                }                else                {                    if (items[i].SubMenuItems.Count > 0)                    {                        GetMenuDataItem(items[i].SubMenuItems, stringToMatch, ref item);                    }                }            }        }         /// <summary>        /// Handles click event of the buttons on the screen.        /// </summary>        /// <param name="sender">Source of the event.</param>        /// <param name="e">Event arguments.</param>        private void Button_Click(object sender, RoutedEventArgs e)        {            MenuDataItem item = new MenuDataItem();            FrameworkElement source = e.Source as FrameworkElement;             switch (source.Name)            {                case "ButtonSecurity": GetMenuDataItem(m_menuDataItems, "Security", ref item);                    break;                default: break;            }             if (item.MenuText != null)            {                item.Command.Execute(null);            }        }         #endregion     }}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t