退出时保留 Silverlight 应用程序中的值
正如这个问题的标题中所说,我试图在应用程序关闭时保留 Timespan 值。情况是这样的...我正在编写一个 Windows 小工具,每次关闭弹出窗口时都会破坏它,并且 Timespan 值也会随之破坏。我想要它,以便每次关闭弹出窗口时它都会保留该值,这将如何实现?
我目前正在做的代码如下。
SilverlightGadgetUtilities.Stopwatch watch = new SilverlightGadgetUtilities.Stopwatch();
private void Application_Startup(object sender, StartupEventArgs e)
{
watch.currentTime();
this.RootVisual = new Page();
}
private void Application_Exit(object sender, EventArgs e)
{
watch.currentTime();
}
这是在我的 Stopwatch 类中:
public TimeSpan? currentTime()
{
current = Elapsed;
return current;
}
public TimeSpan? Elapsed
{
get
{
return new TimeSpan(this.GetElapsedDateTimeTicks() * 10000000);
}
}
其中 GetElapsedDateTimeTicks()
使用 DateTime.Now.Second()
进行计时。
再次感谢!
Just as it says in the title of this question, I am trying to retain a Timespan value when the application is closed. Here's the situation...I am writing a Windows gadget, everytime the flyout window is closed it destroys it, and the Timespan value along with it. I want it so each time the flyout window is closed it retains this value how would this be accomplished?
The code of what I'm currently doing is below.
SilverlightGadgetUtilities.Stopwatch watch = new SilverlightGadgetUtilities.Stopwatch();
private void Application_Startup(object sender, StartupEventArgs e)
{
watch.currentTime();
this.RootVisual = new Page();
}
private void Application_Exit(object sender, EventArgs e)
{
watch.currentTime();
}
And this is in my Stopwatch class:
public TimeSpan? currentTime()
{
current = Elapsed;
return current;
}
public TimeSpan? Elapsed
{
get
{
return new TimeSpan(this.GetElapsedDateTimeTicks() * 10000000);
}
}
Where GetElapsedDateTimeTicks()
is using DateTime.Now.Second()
for the timing.
Thanks again!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以将数据存储在应用程序的独立存储设置中,并在启动时检索它。
以下是在isolatedStorageSettings 中存储信息的示例:
然后您可以使用以下方法检索它:
IsolatedStorageSettings.ApplicationSettings 的作用非常类似于字典。您应该检查是否已存储该名称的设置,如果是,请将其删除或覆盖。覆盖它可以像这样完成:
删除和重新添加的代码将是类似的,除了将 else 块交换为:
You can store data in your application's isolated storage settings and retrieve it on launch.
Here is an example of storing the information in IsolatedStorageSettings:
You would then retrieve it using:
IsolatedStorageSettings.ApplicationSettings acts very much like a dictionary. You should check to see if there is already a setting of that name being stored, and if so, either remove it, or overwrite it. Overwriting it could be done like so:
The code to remove and re-add would be similar, except swapping the else block for: