Я новичок в C# и пытаюсь реализовать INotifyPropertyChanged для моего класса ObsorvableCollection
Но он выдает ошибку, и данные не привязываются. Кто-нибудь, пожалуйста, помогите мне решить эту проблему.
Исключение типа System.ArgumentNullException произошло в
mscorlib.ni.dll, но не было обрабатывается в пользовательском коде
Additional information: Value cannot be null.
Заранее спасибо.
Мой код Xaml:
x:Class="App2.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006 ... esentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:App2"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/marku ... ility/2006"
mc:Ignorable="d">
Мой код CS:
using App2.WrittenLibraries;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Threading.Tasks;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId= ... lcid=0x409
namespace App2
{
///
/// An empty page that can be used on its own or navigated to within a Frame.
///
///
public class Person : INotifyPropertyChanged
{
private string name;
public string Name
{
get { return name; }
set
{
name = value;
OnPropertyChanged("Name");
}
}
private string lastname;
private string v1;
private string v2;
public string Lastname
{
get { return lastname; }
set
{
lastname = value;
OnPropertyChanged("Lastname");
}
}
public event PropertyChangedEventHandler PropertyChanged;
private void OnPropertyChanged(string propertyName)
{
if (propertyName != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
public Person(string v1, string v2)
{
this.v1 = v1;
this.v2 = v2;
}
}
public sealed partial class MainPage : Page
{
public ObservableCollection person = new ObservableCollection();
public MainPage()
{
this.InitializeComponent();
person.Add(new Person("F1", "L1"));
person.Add(new Person("F2", "L2"));
}
private void FilterItem_Click(object sender, RoutedEventArgs e)
{
MenuFlyoutItem selectedItem = sender as MenuFlyoutItem;
if (selectedItem != null)
{
if (selectedItem.Tag.ToString() == "name")
{
Util.debugLog("FILTER BY NAME");
person = new ObservableCollection(person.OrderBy(i => i.Name));
//FilterByUpvotes()();
}
else if (selectedItem.Tag.ToString() == "lname")
{
Util.debugLog("FILTER BY L_NAME");
person = new ObservableCollection(person.OrderBy(i => i.Lastname));
//FilterByOpenForm();
}
else if (selectedItem.Tag.ToString() == "ideas")
{
Util.debugLog("FILTER BY IDEAS");
//person = new ObservableCollection(person.OrderBy(i => i));
//FilterByIdeas();
}
}
}
}
}
Подробнее здесь: https://stackoverflow.com/questions/313 ... lib-ni-dll
Выброшено исключение: «System.ArgumentNullException» в mscorlib.ni.dll ⇐ C#
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Выброшено исключение: «System.InvalidOperationException» в Microsoft.Data.SqlClient.dll.
Anonymous » » в форуме C# - 0 Ответы
- 36 Просмотры
-
Последнее сообщение Anonymous
-