我正在尝试制作一个应用程序,我只是想弄清楚windows phone上的所有东西是如何工作的。
在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;
}
}
Class选项:
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"];
}
}
}
编辑:
我是开放的建议,如果我做错了什么,或者什么可以更好,请告诉我。
发布于 2013-02-23 06:02:26
无限循环?this.voice = value
再次触发set,是什么构成了循环。
您必须声明另一个字段,并将其用作值存储:
private int _voice;
public int voice
{
get
{
return _voice;
}
set
{
settings["voice"] = _voice = (int)value;
}
}
您也必须对第二个属性执行相同的操作。
https://stackoverflow.com/questions/15033851
复制相似问题