创建类的新实例时出现C#StackOverFlowException

Dej*_*ric 0 c# stack-overflow wpf instance

嗯,我遇到了一个奇怪的问题。当我创建类的新实例时,我得到StackOverflowExcepion :)

这是代码:

public partial class PlayerChooser : Window
{
public PlayerChooser()
    {
        InitializeComponent();
        textBoxPlayer1Name.Visibility = Visibility.Hidden;
        textBoxPlayer2Name.Visibility = Visibility.Hidden;
        textBoxPlayer3Name.Visibility = Visibility.Hidden;
        textBoxPlayer4Name.Visibility = Visibility.Hidden;

    }

    public static String player1Name;
    public static String player2Name;
    public static String player3Name;
    public static String player4Name;
    ...

    PlayerChooser.player1Name = textBoxPlayer1Name.Text;
    PlayerChooser.player2Name = textBoxPlayer2Name.Text;
    TwoPlayers501_new twoPlayers501_new = new TwoPlayers501_new();
    twoPlayers501_new.Show();
    ...
}
Run Code Online (Sandbox Code Playgroud)

以及发生异常的类和构造函数

public partial class TwoPlayers501_new : Window
{
    public TwoPlayers501_new()
    {
        InitializeComponent();

        textBlockPlayer1Name.Text = PlayerChooser.player1Name;
        textBlockPlayer2Name.Text = PlayerChooser.player2Name;
    }
    ...
}
Run Code Online (Sandbox Code Playgroud)

预先感谢,这可能有点琐碎...

Gre*_*g D 5

您是否有某个事件处理程序在某处执行根据已更改的属性更改其中一个属性的操作?

短版:这里没有足够的信息来调试您的问题。

建议:调试您的程序,并在获得stackoverflowexception时,签出调用堆栈。我怀疑您的堆栈中存在无限循环的一个或多个方法。