退出时保留 Silverlight 应用程序中的值

发布于 2024-12-17 10:38:56 字数 944 浏览 2 评论 0原文

正如这个问题的标题中所说,我试图在应用程序关闭时保留 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

荒岛晴空 2024-12-24 10:38:56

您可以将数据存储在应用程序的独立存储设置中,并在启动时检索它。

以下是在isolatedStorageSettings 中存储信息的示例:

IsolatedStorageSettings.ApplicationSettings.Add("MySettingName", MySetting);

然后您可以使用以下方法检索它:

IsolatedStorageSettings.ApplicationSettings["MySettingName"];

IsolatedStorageSettings.ApplicationSettings 的作用非常类似于字典。您应该检查是否已存储该名称的设置,如果是,请将其删除或覆盖。覆盖它可以像这样完成:

if (!IsolatedStorageSettings.ApplicationSettings.Contains("MySettingName"))
    IsolatedStorageSettings.ApplicationSettings.Add("MySettingName", MySetting);
else
    IsolatedStorageSettings.ApplicationSettings["MySettingName"] = MySetting;

删除和重新添加的代码将是类似的,除了将 else 块交换为:

else
{
    IsolatedStorageSettings.ApplicationSettings.Remove("MySettingName");
    IsolatedStorageSettings.ApplicationSettings.Add("MySettingName", MySetting);
}

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:

IsolatedStorageSettings.ApplicationSettings.Add("MySettingName", MySetting);

You would then retrieve it using:

IsolatedStorageSettings.ApplicationSettings["MySettingName"];

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:

if (!IsolatedStorageSettings.ApplicationSettings.Contains("MySettingName"))
    IsolatedStorageSettings.ApplicationSettings.Add("MySettingName", MySetting);
else
    IsolatedStorageSettings.ApplicationSettings["MySettingName"] = MySetting;

The code to remove and re-add would be similar, except swapping the else block for:

else
{
    IsolatedStorageSettings.ApplicationSettings.Remove("MySettingName");
    IsolatedStorageSettings.ApplicationSettings.Add("MySettingName", MySetting);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文