我正在尝试使用单选按钮和代表进行过滤。基本上我想要一个硬编码的列表,它会像伪数据库一样工作,然后只显示列表中的某些项目,具体取决于按下哪个按钮。我无法从另一个类访问我的列表(可观察集合)
我有一个Apartment.cs
类有一个名称和ID属性,没有别的。
另一类我是Apts.cs
:
public class Apts
{
private ObservableCollection<Apartment> apartments;
public ObservableCollection<Apartment> Apartments { get; set; }
public Apts()
{
apartments = new ObservableCollection<Apartment>()
{
new Apartment() {Name = "Name1", ID = 1},
new Apartment() {Name = "Name2", ID = 2},
new Apartment() {Name = "Name3", ID = 3},
};
}
}
我试图进入公寓属性,它应该是列表中(我错了?),并将其作为参数传递到ListParis(ObservableCollection<Apartment>)
方法我写的。此代码是MainPage.xaml.cs
public void AssignDelegates()
{
if (parisButton.IsPressed)
{
myFunc = DelActions.ListParis(Apartments);
}
}
,但我得到一个错误说:
CS0103 The name 'Apartments' does not exist in the current context
为什么我不能访问列表?
我有点忘了,我需要初始化O访问的性能。但我认为你使用的语法和我使用的语法是一样的。你能否详细说明两者的区别? – numme27
此外,我收到此错误: 'CS0029 \t不能隐式地将类型'System.Collections.ObjectModel.ObservableCollection'转换为'System.Func ,System.Collections.Generic.IEnumerable >'\t' –
numme27
消息说这一切,你试图传递参数的类型System.Collections.ObjectModel.ObservableCollection但你的方法是期待另一个('System.Func ,System.Collections.Generic.IEnumerable ) –
BladeMaster