我正在尝试制作一个应用程序,而我只是想弄清楚 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"];
}
}
}
编辑 :
如果我做错了什么或者有什么更好的,我愿意接受建议,请告诉我。