I'm trying to create a data template for a dashboard menu. It has 4 four options for different menus. So I decided to go with data templates. Here so the gist of my code.
xaml
<StackPanel Grid.Row="1" x:Name="ControlPanelMenuContainer">
<ItemsControl ItemsSource="{Binding MenuItemsNeeded}" Name="DashboardButtonList">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Button Command="{Binding Command}">
<Button.Content>
<Grid>
<TextBlock Text="{Binding Text}"></TextBlock>
<UserControl:Icomoon IcoIcon="{Binding Icon}" />
</Grid>
</Button.Content>
</Button>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>
code behind Menu Items Class
class MenuItems
{
private ICommand _PrivateCommandName;
private string _PrivateIcon;
private string _PrivateTitle;
public ICommand CommandName
{
get { return _PrivateCommandName; }
private set { _PrivateCommandName = value; }
}
public string Icon
{
get { return _PrivateIcon; }
private set { _PrivateIcon = value; }
}
public string Title
{
get { return _PrivateTitle; }
private set { _PrivateTitle = value; }
}
public MenuItems(string title, string icon, ICommand command)
{
Icon = icon;
Title = title;
CommandName = command;
}
}
Code Behind the Condensed Main object
MVVM.IControllerMVVM MVVM = new MVVM.IControllerMVVM();
List<MenuItems> MenuItemsNeeded = new List<MenuItems>();
if(User_Who_IsLoggedOn == 0)
{
MenuItemsNeeded.Add(new MenuItems("Data Matrix", "Document", MVVM.GotoDataMatrixDowntimeCommand));
MenuItemsNeeded.Add(new MenuItems("Documents", "Document", MVVM.GotoDocumentsCommand));
MenuItemsNeeded.Add(new MenuItems("Inventory", "FilledBox", MVVM.GotoInventoryCommand));
MenuItemsNeeded.Add(new MenuItems("CorkBoard", "Comment", MVVM.GotoCorkboardCommand));
MenuItemsNeeded.Add(new MenuItems("Quality Assurance", "Measure", MVVM.GotoQCQACommand));
MenuItemsNeeded.Add(new MenuItems("Statistics", "LineGraph", MVVM.GotoStatisticsCommand));
MenuItemsNeeded.Add(new MenuItems("Safety", "Warning", MVVM.GotoSafetySheetCommand));
MenuItemsNeeded.Add(new MenuItems("Calendar", "Warning", MVVM.GotoEditorCommand));
}
So as you can see in the XAML part of the code I have bound all my properties to the appropriate objects. yet nothing shows up properly. This is my first time using the items control object, and yes I am still learning Bindings. I have been watching videos and reading up on articles online and on stackoverflow. But none of which I believe fit my needs. Which is a binding with a binding and more. Right now I'm not quite sure why nothing is even populating the stackpanel at all.
EDIT as to PHOENIX Answer
I've added a public property for MenuItemsNeeded
private List<MenuItems> _MenuItemsNeeded = new List<MenuItems>();
public List<MenuItems> MenuItemsNeeded
{
get { return _MenuItemsNeeded; }
}
Everything works except the binding for the Command name section now.
<Button Height="40" Grid.Row="1" Style="{StaticResource NavButton}" Command="{Binding CommandName}">