无法向资源添加用户类
本文关键字:用户 添加 资源 | 更新日期: 2023-09-27 18:10:17
这是我的类:
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类我使用无参数构造函数,但它仍然不起作用。有人能帮帮我吗?
你需要制作
ObservableCollection<string> MenuList { get; private set; }
public ObservableCollection<string> MenuList { get; set; }
c#的默认访问器在嵌套类中是内部的或私有的。
访问修饰符(c#编程指南)
类的默认访问修饰符?
还有这个答案