我正在通过 WPF 应用程序创建一个 CRUD 应用程序来学习基础知识。但是,当我调用 SetItem() 来更改 ObservableCollection 中的元素时,我遇到了“由于其保护级别而无法访问”的情况。
我尝试过但没有解决问题的事情:
有没有人有任何可能有帮助的想法或其他建议?提前致谢!
错误 1 'System.Collections.ObjectModel.Collection.SetItem(int, WpfApplication1.User)' 由于其保护级别 C:\Users\sliu\Documents\Visual Studio 2013\Projects\WpfApplication1\WpfApplication1\MainWindow.xaml 而无法访问。 cs 70 27 WpfApplication1
代码失败的地方:
private void onKeyDownHandler(object sender, System.Windows.Input.KeyEventArgs e)
{
BindingExpression binding = addUser.GetBindingExpression(System.Windows.Controls.TextBox.TextProperty);
binding.UpdateSource();
User temp_user;
if ((e.Key == Key.Return) && !addUser.Text.Equals(""))
{
if (modify)
{
**//THIS IS WHERE THE PROBLEM IS
users.SetItem(index, new User() { Name = addUser.Text });**
}
else
{
users.Add(new User() { Name = addUser.Text });
}
}
}
Run Code Online (Sandbox Code Playgroud)
完整代码:
using …Run Code Online (Sandbox Code Playgroud)