wpf - How distinguish between objects type c# -
i creating basketball wpf app displays hometeam
, awayteam
. have created player
object , in main window have created observablecollection
of player objects both home (homeplayerslist
) , away teams (awayplayerslist
). have used inotifypropertychanged
interface on player object when isingame
bool true player gets added 1 of 2 observablecollection<player>
depending on count. (if list 1 observablecollection<player> hometeam
or observablecollection<player> awayteam
count 5, rest gets added substitution list observablecollection<team> homesub
or observablecollection<team> awaysub
.)
but trying distinguish whether player in home or away team, , depending on list player in, player added new list of home or away.
public static observablecollection<player> homeplayerslist; public static observablecollection<player> awayplayerslist; public static observablecollection<player> hometeam = new observablecollection<player>(); public static observablecollection<player> awayteam = new observablecollection<player>(); public static observablecollection<player> homesub = new observablecollection<player>(); public static observablecollection<player> awaysub = new observablecollection<player>(); public static int homesubcount = 7; public class player: inotifypropertychanged { public static bool ishome = true; private static int totalselected = 1; public string id { get; set; } //player id public string firstname { get; set; } //player first name public string secondname { get; set; } //player second name public string knownname { get; set; } //player known name public string position { get; set; } //player position public string number { get; set; } //player number public bool isingame; public bool isingame { { return isingame; } set { if (value != isingame) { isingame = value; if (isingame) { onpropertychanged("isingame", true); } else { onpropertychanged("isingame", false); } } } } protected void onpropertychanged(propertychangedeventargs e) { propertychangedeventhandler handler = propertychanged; if (handler != null) handler(this, e); } protected void onpropertychanged(string propertyname, bool state) { onpropertychanged(new propertychangedeventargs(propertyname)); if (state) { if (totalselected > 5 + mainwindow.homesubcount) { this.isingame = false; return; } if (mainwindow.hometeam.count < 5) mainwindow.hometeam.add(this); else { if (mainwindow.homesub.count < mainwindow.homesubcount) { mainwindow.homesub.add(this); } } totalselected++; } else { if (searchforme(mainwindow.hometeam) != null) { mainwindow.hometeam.remove(searchforme(mainwindow.hometeam)); totalselected--; return; } if (searchforme(mainwindow.homesub) != null) { mainwindow.homesub.remove(searchforme(mainwindow.homesub)); totalselected--; return; } } } private team searchforme(observablecollection<team> oct) { return oct.where(i => i.number == this.number).singleordefault(); } public event propertychangedeventhandler propertychanged;`enter code here` }
paste in player class property
observablecollection<player> currnetin { get; set; }
and set property, if add player in collection. or have misunderstood question.
Comments
Post a Comment