我有一个班级:
namespace Golf
{
public class Game : INotifyPropertyChanged
{
public string Player
{
get { return Player; }
set
{
Player = value;
NotifyPropertyChanged("Player");
}
}
public int Hole
{
get { return Hole; }
set
{
Hole = value;
NotifyPropertyChanged("Hole");
}
}
public int Strokes
{
get { return Strokes; }
set
{
Strokes = value;
NotifyPropertyChanged("Strokes");
}
}
public Game(string player, int hole, int strokes)
{
Player = player;
Hole = hole;
Strokes = strokes;
}
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged(String propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
}
}
在我的MainPage的构造函数中,我填写了listview:
public MainPage()
{
// Left out other code
listViewGames.ItemsSource = games;
}
在我的xaml中,我有listview:
<ListView x:Name="listViewGames" ItemTemplate="{StaticResource templateGames}"></ListView>
将游戏添加到游戏列表中的点击事件的代码:
Game game = new Game(listViewPlayers.SelectedItem.ToString(), Int32.Parse(listViewHoles.SelectedItem.ToString()), (int)sliderStrokes.Value);
games.Add(game);
但是我的类中的语法似乎有问题,我收到一个错误:System.StackOverflowException出现在......
任何人都可以帮助我吗?
答案 0 :(得分:0)
因为你返回相同的属性:) 替换这个:
data.table
使用:
public string Player
{
get { return Player; }
set
{
Player = value;
NotifyPropertyChanged("Player");
}
}
和其他人