1

This is my class:

public class MenuMaker
{
    public MenuMaker()
    {
        NumbersOfItems = 5;
        MenuList = new ObservableCollection<string>();
        UpdateMenu();
    }

    public int NumbersOfItems { get; set; }
    ObservableCollection<string> MenuList { get; private set; }
    public string GeneratedData { get; private set; }

    string[] firthMill = new string[] { "Red Borshc ", "Green Borshc ", "Soup " };
    string[] secondMill = new string[] { "with salat ", "with porrage " };
    string[] drink = new string[] { "and tee", "and coffee", "and juce", "and vodka" };

    public void UpdateMenu()
    {
        MenuList.Clear();
        Random random = new Random();
        string newMill;
        for (int i = 0; i < NumbersOfItems; i++)
        {
            newMill = "";
            newMill += firthMill[random.Next(firthMill.Length)] + secondMill[random.Next(secondMill.Length)] +
                drink[random.Next(drink.Length)];
            MenuList.Add(newMill);
        }
        DateTime nowIs = DateTime.Now;
        GeneratedData = "This menu was generated on " + nowIs.ToString();
    }
}

and here I want to add it to the resources:

<Window x:Class="WpfApplication1.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:WpfApplication1"
    Title="MainWindow" Height="350" Width="525">
<Window.Resources>
    <local:MenuMaker x:Key="menu"/>
</Window.Resources>
</Window>

but have a problem:

the type "MenuMaker" does not include any accessible constructors

I searched a lot, but does not find correct answer for my case. I can not understand: in my MenuMaker class I use parameterless constructor, but it still doesn't work. Can somebody help me?

Alex D.
  • 115
  • 2
  • I can't reproduce your error message, but to get a successful compilation I need to declare _public ObservableCollection MenuList { get; private set; }_ – Steve Aug 29 '15 at 12:48

1 Answers1

0

You need to make

ObservableCollection<string> MenuList { get; private set; }

public  ObservableCollection<string> MenuList { get; set; }

The default accessor in C# is internal or private in a nested class.

Access Modifiers (C# Programming Guide)

Default access modifier of a class ?

And this answer here.

Community
  • 1
  • 1