まず、この質問が完全に意味をなさない場合はお詫び申し上げます。私は C# と XAML に関してはまったくの初心者です。
私はこのクラスの人々を作成しました:
class Student
{
private string studentID;
public string StudentID
{
get { return studentID; }
set
{
studentID = value;
NotifyPropertyChanged("StudentID");
}
}
private string firstName;
public string FirstName {
get { return firstName; }
set
{
firstName = value;
NotifyPropertyChanged("FirstName");
}
}
private string surname;
public string Surname
{
get { return surname; }
set
{
surname = value;
NotifyPropertyChanged("Surname");
}
}
private string group;
public string Group
{
get { return group; }
set
{
group = value;
NotifyPropertyChanged("Group");
}
}
private int cValue;
public int CValue
{
get { return cValue; }
set
{
cValue = value;
NotifyPropertyChanged("CValue");
}
}
private string teacher;
public string Teacher
{
get { return teacher; }
set
{
teacher = value;
NotifyPropertyChanged("Teacher");
}
}
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged([CallerMemberName] string caller = "")
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(caller));
}
}
public Student() { }
public Student(string studentID, string firstName, string surname, string group, int cValue, string teacher)
{
StudentID = studentID;
FirstName = firstName;
Surname = surname;
Group = group;
CValue = cValue;
Teacher = teacher;
}
// strings used to create random students
private static readonly string[] firstNames = { "Adam", "Bob", "Carl", "David", "Edgar", "Frank", "George", "Harry", "Isaac", "Jesse", "Ken", "Larry" };
private static readonly string[] surnames = { "Adamson", "Bobson", "Carlson", "Davidson", "Edgarson", "Frankson", "Georgeson", "Harryson", "Isaacson", "Jesseson", "Kenson", "Larryson" };
private static readonly string[] groups = { "6a", "5b" };
private static readonly string[] teachers = { "Fred", "Jim"};
// method to create random students
public static IEnumerable<Student> CreateStudents(int count)
{
var people = new List<Student>();
var r = new Random();
for (int i=0; i< count; i++)
{
StringBuilder builder = new StringBuilder();
builder.Append("A");
builder.Append(i.ToString());
string num = builder.ToString();
var s = new Student()
{
StudentID = num,
FirstName = firstNames[r.Next(firstNames.Length)],
Surname = surnames[r.Next(surnames.Length)],
Group = groups[r.Next(groups.Length)],
Teacher = teachers[r.Next(teachers.Length)]
};
people.Add(s);
}
return people;
}
}
次に、これらの人物オブジェクトのリストを作成しました。このリストをリスト/グリッド ビューに簡単にバインドできます。
私がやりたいのは、各アイテムにプラスとマイナスのボタンを付けて、その人の CValue から 1 を追加または削除することです。(デモンストレーションのために写真をアップロードしますが、許可しません...)
XAML をレイアウトし、私のようなバカでも理解できる方法でバインディングを追加するにはどうすればよいでしょうか?
ありがとう!