windows-phone-7.1在一组之后立即退出应用程序

时间:2013-02-22 21:56:21

标签: c# set windows-phone-7.1 windows-phone

我正在尝试创建一个应用程序,我只想弄清楚Windows手机上的一切是如何工作的。

在Windows Phone模拟器中,我尝试运行我的应用程序但它只返回上一个屏幕而没有任何错误。 (编译器也没有给我任何错误。)

即使我除了this.voice = value之外我没有放任何东西,它仍然无效。

这是发生错误的代码:

   // volume of the voice of the commentator;
   public int voice { 
        get 
        { 
            return voice; 
        }
        set 
        {
            settings["voice"] = this.voice = (int)value;  // right here it just stops.
        } 

我调用此函数的代码是:

public partial class MainPage : PhoneApplicationPage
{
    // Constructor
    public MainPage()
    {
        InitializeComponent();
       // example :: ExceptionHandler.newException("er is geen exception");

        Option option = new Option();
        option.backgroundMusic = 22; // here
        option.voice = 32; // here

    }
}

总的来说:

主页:

public partial class MainPage : PhoneApplicationPage
{
    // Constructor
    public MainPage()
    {
        InitializeComponent();
       // example :: ExceptionHandler.newException("er is geen exception");

        Option option = new Option();
        option.backgroundMusic = 22;
        option.voice = 32;

    }
}

班级选项:

    public class Option
    {
    // isolated storage settings connection.
    private static IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings; 

    // volume of the backgroundMusic;
    public int backgroundMusic { 
        get 
        { 
            return backgroundMusic; 
        } 
        set 
        {
            settings["backgroundMusic"] = this.backgroundMusic = (int)value; 
        } 
    } 

    // volume of the voice of the commentator;
    public int voice { 
        get 
        { 
            return voice; 
        }
        set 
        {
            settings["voice"] = this.voice = (int)value; 
        } 
    }





    public Option()
    {
        // If the keys doesn't exists
        if (!settings.Contains("backgroundMusic") && !settings.Contains("voice"))
        {

            // Create the settings.
            settings.Add("backgroundMusic", (int)50 );
            settings.Add("voice", (int)50);
        }
        // If the key exists, retrieve the value and set the properties of backgroundMusic and voice
        else
        {
            this.backgroundMusic = (int)settings["backgroundMusic"];
            this.voice = (int)settings["voice"];
        }
    }
}

编辑:

如果我做了其他错误或有什么可能更好的话,我愿意接受建议,请告诉我。

1 个答案:

答案 0 :(得分:0)

无限循环? this.voice = value再次触发该集合,是一个循环。

您必须声明另一个字段并将其用作值存储:

private int _voice;
public int voice
{ 
    get 
    { 
        return _voice; 
    }
    set 
    {
        settings["voice"] = _voice = (int)value; 
    } 
}

你也必须对第二个属性做同样的事情。