C2.01 Security: hint for using Main menu. (Wpf) - chempkovsky/CS2WPF-and-CS2XAMARIN GitHub Wiki
Take a look at the _MainMenu
-var
#region MainMenu
IEnumerable<IWebServiceFilterMenuInterface> _MainMenu = new ObservableCollection<IWebServiceFilterMenuInterface>()
{
new WebServiceFilterMenuViewModel() { Id = "000", Caption="Home", IconName="Home", IconColor="Primary", Data="HomeUserControl", Command=RoutedCommandExt.MainMenuCommand},
...
}
And take a look at the definition of WebServiceFilterMenuViewModel
-class
public class WebServiceFilterMenuViewModel: IWebServiceFilterMenuInterface, INotifyPropertyChanged
{
#region INotifyPropertyChanged
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged([CallerMemberName] string name = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
}
#endregion
protected string _Id;
public string Id { get { return _Id; } set { if(_Id != value) { _Id = value; OnPropertyChanged(); } } }
protected string _Caption;
public string Caption { get { return _Caption; } set { if(_Caption != value) { _Caption = value; OnPropertyChanged(); } } }
protected string _IconName;
public string IconName { get { return _IconName; } set { if(_IconName != value) { _IconName = value; OnPropertyChanged(); } } }
protected string _IconColor;
public string IconColor { get { return _IconColor; } set { if(_IconColor != value) { _IconColor = value; OnPropertyChanged(); } } }
protected bool _Enabled;
public bool Enabled { get { return _Enabled; } set { if(_Enabled != value) { _Enabled = value; OnPropertyChanged(); } } }
protected dynamic _Data;
public dynamic Data { get { return _Data; } set { if(_Data != value) { _Data = value; OnPropertyChanged(); } } }
protected dynamic _Command;
public RoutedCommand Command { get { return _Command; } set { if (_Command != value) { _Command = value; OnPropertyChanged(); } } }
}
Data
-property is of dynamic
-type. In our "hands of lab" Data
-property held user control name. It was done to simplify explanation and understanding. However, a developer can define a Data property with a complex structure. Here is an example for Angular-project:
{ path: 'LitManuscriptView/:depth/LitBookView/:p2x0/Manuscript', loadChildren: () => import('./components/lit-book-view/lit-book-view-rl-lazy.module').then(m => m.LitBookViewRlLazyModule), data: { filterMaxHeight: 2, maxHeight: 10, showFilter: true, title: 'List of LitBookView' } },
Note: After changing the structure of Data property two methods need to be rewritten
public void ExecutedMainMenuCommand(object sender, ExecutedRoutedEventArgs e) {...}
public void CanExecuteMainMenuCommand(object sender, CanExecuteRoutedEventArgs e) {...}