我有一个名为Player的课程:
public class Player
{
public string Name { get; set; }
public ScoreCard Card { get; set; }
public bool ReadyToStart { get; set; }
public override string ToString()
{
return (Name + " - " + this.Card.TotalScore);
}
}
使用对上述类的服务引用的wpf客户端。当我想将一个玩家数组设置为ListBox的ItemSource时,重写的ToString方法不会替换该类:
public void SendAllPlayers(Player[] players)
{
if (this.Dispatcher.Thread == System.Threading.Thread.CurrentThread)
{
try
{
lbPlayers.ItemsSource = players;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
else
this.Dispatcher.BeginInvoke(new GuiUpdateDelegate(SendAllPlayers), new object[] { players });
}
结果如下所示:
重写的ToString方法是否不会延续服务引用?有办法解决这个问题吗?
感谢。