我在 C# MAINWINDOW.xaml.cs 中有一个这样的字符串集合
public class NameList : ObservableCollection<Shortcuts>
{
public NameList() : base()
{
Add(new Shortcuts("ctrl", "b","s"));
Add(new Shortcuts("ctrl", "b","m"));
Add(new Shortcuts("ctrl", "b","p"));
Add(new Shortcuts("ctrl", "b","1"));
}
}
public class Shortcuts
{
private string firstkey;
private string secondkey;
private string lastkey;
public Shortcuts(string first, string second, string last)
{
this.firstkey = first;
this.secondkey = second;
this.lastkey= last;
}
public string Firstkey
{
get { return firstkey; }
set { firstkey = value; }
}
public string Secondkey
{
get { return secondkey; }
set { secondkey = value; }
}
public string Lastkey
{
get { return lastkey; }
set { lastkey = value; }
}
}
}
然后在 MainWindow.xaml 本身我有一个组合框,我想将这些项目绑定到组合框,所以这就是我所做的
<Window x:Class="Testing_learning.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:c="clr-namespace:Testing_learning"
Title="Outlook Context Settings" Height="350" Width="525">
<Window.Resources>
<c:ListName Key ="NameListData"/>
</Window.Resources>
哦顺便说一句,项目名称是Testing_learning这就是为什么会有这个
xmlns:c="clr-namespace:Testing_learning"
但问题是当我添加这行代码时
<Window.Resources>
<c:ListName Key ="NameListData"/>
</Window.Resources>
我在 c:ListName 收到错误,找不到类型 ListName 为什么会这样?有什么想法吗?
截图 1
截图 2