|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Collections.ObjectModel; |
| 4 | +using System.ComponentModel; |
| 5 | +using System.Text; |
| 6 | +using ViewModel.Commands; |
| 7 | +//using System.Windows.Controls; |
| 8 | + |
| 9 | +namespace ViewModel |
| 10 | +{ |
| 11 | + /// <summary> |
| 12 | + /// ViewModel for MainPage |
| 13 | + /// </summary> |
| 14 | + public class MainPageViewModel : INotifyPropertyChanged |
| 15 | + { |
| 16 | + #region Properties |
| 17 | + /// <summary> |
| 18 | + /// Collection of pages for the main navigation menu |
| 19 | + /// </summary> |
| 20 | + public ObservableCollection<MainMenuNavigationItemData> MainNavigationItems { get; } = new ObservableCollection<MainMenuNavigationItemData>() |
| 21 | + { |
| 22 | + new MainMenuNavigationItemData("Profile", "ProfilePage.xaml", null) |
| 23 | + }; |
| 24 | + |
| 25 | + |
| 26 | + private string currentVisiblePage; |
| 27 | + /// <summary> |
| 28 | + /// Page that is currently visible on the frame |
| 29 | + /// </summary> |
| 30 | + public string CurrentVisiblePage |
| 31 | + { |
| 32 | + get |
| 33 | + { |
| 34 | + return currentVisiblePage; |
| 35 | + } |
| 36 | + set |
| 37 | + { |
| 38 | + currentVisiblePage = value; |
| 39 | + OnPropertyChanged("CurrentVisiblePage"); |
| 40 | + } |
| 41 | + } |
| 42 | + |
| 43 | + private string title; |
| 44 | + /// <summary> |
| 45 | + /// Title shown on top of the page |
| 46 | + /// </summary> |
| 47 | + public string Title |
| 48 | + { |
| 49 | + get |
| 50 | + { |
| 51 | + return title; |
| 52 | + } |
| 53 | + set |
| 54 | + { |
| 55 | + title = value; |
| 56 | + OnPropertyChanged("Title"); |
| 57 | + } |
| 58 | + } |
| 59 | + |
| 60 | + /// <summary> |
| 61 | + /// Handles the click events of the main menu buttons |
| 62 | + /// </summary> |
| 63 | + public NavigateButtonCommand NavigateButtonCommand { get; set; } |
| 64 | + #endregion |
| 65 | + |
| 66 | + #region constructor |
| 67 | + /// <summary> |
| 68 | + /// Creates a new viewmodel for MainPage |
| 69 | + /// </summary> |
| 70 | + public MainPageViewModel() |
| 71 | + { |
| 72 | + NavigateButtonCommand = new NavigateButtonCommand(this); |
| 73 | + } |
| 74 | + #endregion |
| 75 | + |
| 76 | + #region MainMenuNavigationItemData |
| 77 | + /// <summary> |
| 78 | + /// The data for a menu item on the main navigation menu |
| 79 | + /// </summary> |
| 80 | + public struct MainMenuNavigationItemData |
| 81 | + { |
| 82 | + /// <summary> |
| 83 | + /// Creates an item of data for the main navigation menu |
| 84 | + /// </summary> |
| 85 | + /// <param name="title">The title of the page shown on the top of the main page</param> |
| 86 | + /// <param name="page">The page to be navigated to</param> |
| 87 | + /// <param name="extraInformation">Optional extra information to be given when navigating</param> |
| 88 | + public MainMenuNavigationItemData(string title, string page, object extraInformation) |
| 89 | + { |
| 90 | + Title = title; |
| 91 | + Page = page; |
| 92 | + ExtraInformation = extraInformation; |
| 93 | + } |
| 94 | + |
| 95 | + /// <summary> |
| 96 | + /// The title of the page shown on the top of the main page |
| 97 | + /// </summary> |
| 98 | + public string Title { get; set; } |
| 99 | + /// <summary> |
| 100 | + /// The page to be navigated to |
| 101 | + /// </summary> |
| 102 | + public string Page { get; set; } |
| 103 | + /// <summary> |
| 104 | + /// Optional extra information to be given when navigating |
| 105 | + /// </summary> |
| 106 | + public object ExtraInformation { get; set; } |
| 107 | + } |
| 108 | + #endregion |
| 109 | + |
| 110 | + #region Property change notification |
| 111 | + /// <summary> |
| 112 | + /// Occurs when a property value changes. |
| 113 | + /// </summary> |
| 114 | + public event PropertyChangedEventHandler PropertyChanged; |
| 115 | + /// <summary> |
| 116 | + /// Triggers the PropertyChanged event |
| 117 | + /// </summary> |
| 118 | + /// <param name="propertyName">The property which is changed</param> |
| 119 | + private void OnPropertyChanged(string propertyName) |
| 120 | + { |
| 121 | + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); |
| 122 | + } |
| 123 | + #endregion |
| 124 | + } |
| 125 | +} |
0 commit comments