我是 XAML 和 C# 的初学者,我有下面的代码,但我不知道要修改什么来解决这两个错误。
Requested value 'PropertyChanged' was not found.
和
'Cautare.get' must declare a body because it is not marked abstract, extern, or partial
这是 XAML
<TextBox x:Name="textbutton1" Text="{Binding Cautare, UpdateSourceTrigger=PropertyChanged}"/>
<ListBox Grid.Row="1" x:Name="ListBox" Margin="0,0,-12,0" ItemsSource="{Binding Sursa.View}">
和代码隐藏
public partial class MainPage : PhoneApplicationPage
{
public CollectionViewSource Sursa { get; set; }
public string Cautare { get;
set
{
if (!string.IsNullOrEmpty(Cautare))
Filtreaza();
Sursa.View.Refresh();
}
}
private void Filtreaza()
{
Sursa.Filter -= new FilterEventHandler(Filtru);
Sursa.Filter += new FilterEventHandler(Filtru);
}
private void Filtru(object sender, FilterEventArgs e)
{
var src = e.Item as Rind;
if (src == null) e.Accepted = false;
else if (src.Text != null && !src.Text.Contains(Cautare)) e.Accepted = false;
}
public ObservableCollection<Rind> Lista { get; set; }
public MainPage()
{
Lista = new ObservableCollection<Rind>
{
new Rind { Text = "abcd"},
new Rind { Text = "asdf"},
new Rind { Text = "asdzx"},
new Rind { Text = "adffgd"},
new Rind { Text = "asdfgea"},
};
InitializeComponent();
Sursa = new CollectionViewSource();
Sursa.Source = Lista;
DataContext = this;
}
public class Rind
{
public string Text { get; set; }
}
}
我已经阅读了有关 CollectionViewSource 和绑定的其他类似问题。
我的直觉说这是一个普遍的问题,但经过两个小时的测试,我已经进入了大脑阻塞循环,无法再清楚地“看到”它了。所以我在寻求帮助。谢谢!