private void ResolveAllMADViewModels() { var BarehandCategoryVM = _runtime.Container.ResolveWithParameters <CategoriesViewModel>(new Dictionary <string, object> { { "deserializedContents", _madContent }, { "level1ID", @"Barehand" } }); var HotStickCategoryVM = _runtime.Container.ResolveWithParameters <CategoriesViewModel>(new Dictionary <string, object> { { "deserializedContents", _madContent }, { "level1ID", @"Hot Stick" } }); var PhaseToPhaseCategoryVM = _runtime.Container.ResolveWithParameters <CategoriesViewModel>(new Dictionary <string, object> { { "deserializedContents", _madContent }, { "level1ID", @"Phase to Phase" } }); _VMsICanNavigateTo.AddTo <MADViewModel>(BarehandCategoryVM); _VMsICanNavigateTo.AddTo <MADViewModel>(HotStickCategoryVM); _VMsICanNavigateTo.AddTo <MADViewModel>(PhaseToPhaseCategoryVM); _MADVM = _runtime.Container.ResolveWithParameters <MADViewModel>(new Dictionary <string, object> { { "deserializedContents", _madContent }, { "viewModelsICanNavigateTo", _VMsICanNavigateTo.GetAllFrom <MADViewModel>() } }); }
// We want to dynamically generate the buttons and their text based on the number of "IDs" gathered in the View Model // Unfortunately, XAML doesn't support looping statements of any kind, so I had to move the parent XAML code into this code-behind class // This feels messy, but I'm sure there's a better way by creating a custom control? private Grid CreateGridOfButtons(MADViewModel vmContext) { var tileGrid = new Grid { Padding = ButtonGridPadding, VerticalOptions = ButtonGridVertOptions, HorizontalOptions = ButtonGridHorzOptions, RowSpacing = ButtonGridRowSpacing, ColumnSpacing = ButtonGridColumnSpacing, RowDefinitions = CreateRowDefinitions(vmContext), ColumnDefinitions = CreateColumnDefinitions(vmContext) }; for (var i = 0; i < vmContext.GetIDsCount(); i++) { tileGrid.Children.Add(new ThemedNavigationButton { Text = vmContext.GetParentIDText(i), Command = vmContext.NavigateToViewModel(i), BackgroundColor = ThemedNavigationButton.ButtonBackgroundColor, TextColor = ThemedNavigationButton.ButtonTextColor, FontSize = ThemedNavigationButton.ButtonFontSize, FontAttributes = ThemedNavigationButton.ButtonFontAttributes }, 0, i); } return(tileGrid); }
private ColumnDefinitionCollection CreateColumnDefinitions(MADViewModel vmContext) { var columnDefinitionCollection = new ColumnDefinitionCollection(); columnDefinitionCollection.Add(new ColumnDefinition { Width = ButtonGridColumnDefWidth }); return(columnDefinitionCollection); }
private RowDefinitionCollection CreateRowDefinitions(MADViewModel vmContext) { var rowDefinitionCollection = new RowDefinitionCollection(); for (var i = 0; i < vmContext.GetIDsCount(); i++) { rowDefinitionCollection.Add(new RowDefinition { Height = ButtonGridRowDefHeight }); } return(rowDefinitionCollection); }