这是我的班级:
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();
}
}
在这里我想将它添加到资源中:
<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>
但有问题:
the type "MenuMaker" does not include any accessible constructors
我搜索了很多,但找不到正确的答案。我无法理解:在我的MenuMaker类中,我使用无参数构造函数,但它仍然无法工作。有人可以帮帮我吗?
答案 0 :(得分:0)
你需要制作
ObservableCollection<string> MenuList { get; private set; }
public ObservableCollection<string> MenuList { get; set; }
C#中的默认访问器是嵌套类中的内部或私有。
Access Modifiers (C# Programming Guide)