//****************************************************************************************************** // 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 { /// /// Interaction logic for HomeUserControl.xaml /// public partial class HomeUserControl : UserControl { #region [ Members ] // Fields private readonly ObservableCollection m_menuDataItems; #endregion #region [ Constructors ] /// /// Creates an instance of . /// public HomeUserControl() { InitializeComponent(); // Load Menu XmlRootAttribute xmlRootAttribute = new XmlRootAttribute("MenuDataItems"); XmlSerializer serializer = new XmlSerializer(typeof(ObservableCollection), xmlRootAttribute); using (XmlReader reader = XmlReader.Create(FilePath.GetAbsolutePath("Menu.xml"))) { m_menuDataItems = (ObservableCollection)serializer.Deserialize(reader); } } #endregion #region [ Methods ] /// /// Recursively finds menu item to navigate to when a button is clicked on the UI. /// /// Collection of menu items. /// Item to search for in menu items collection. /// Returns a menu item. private void GetMenuDataItem(ObservableCollection 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); } } } } /// /// Handles click event of the buttons on the screen. /// /// Source of the event. /// Event arguments. 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 } }