简体   繁体   English

简单的桌面小工具在两次运行之间不会保存其数据

[英]Simple desktop gadget won't save its data between runs

I'm trying to write a very simple Windows 7 gadget, which is easy enough. 我正在尝试编写一个非常简单的Windows 7小工具。 But I can't get any of the data I'm saving with System.Gadget.Settings.write/read ( writeString / readString ) to persist between runs of the gadget. 但是我无法获得使用System.Gadget.Settings.write/readwriteString / readString )保存的任何数据来在小工具运行之间持久保存。 I know it can be done, because all the other Microsoft gadgets do it. 我知道可以做到的,因为所有其他Microsoft小工具都可以做到。 I'm obviously missing something crucial, but can't see it. 我显然错过了一些关键的东西,但看不到。

This is a very simple cut down example: 这是一个非常简单的示例:

<html>
<head>
<meta http-equiv="MSThemeCompatible" CONTENT="yes" />
<meta http-equiv="Content-Type" content="text/html; charset=Unicode" />
<title>test</title>
    <script type="text/javascript">
        function save() {
            var e = document.getElementById("name");
            if (e && e.value) {
                System.Gadget.Settings.write("name", e.value);
                prompt("turnedout", System.Gadget.Settings.read("name"));
            }
        }

        function load() {
            var t = System.Gadget.Settings.read("name");
            prompt("turnedout", t);
        }
    </script>
</head>
<body scroll="no" unselectable="on" onload='load()'>
    <label for='name'>Name</label>
    <input id='name'>
    <input type="button" value='Save' onclick='save()' />
</body>
</html>

I've traced through the code and everything appears to go in the right places. 我已经遍历了代码,一切似乎都在正确的地方进行。 What's missing? 缺少了什么?

Even I had the same issue, but when I moved the System.Gadget.Settings.write("name", e.value); 即使我也遇到了同样的问题,但是当我移动System.Gadget.Settings.write(“ name”,e.value);时, to the html which is specified in the gadget.xml file, it wrote to the settings.ini file properly 到gadget.xml文件中指定的html,它已正确写入settings.ini文件

Gadgets don't work like desktop applications with regard to settings. 小工具在设置方面不像桌面应用程序那样工作。 The settings are per instance of a gadget. 设置是针对小工具的每个实例。 Close the instance and you lose the settings. 关闭实例,您将丢失设置。 There are other limitations as well. 还有其他限制。 There's a good explanation at: http://dotnetslackers.com/articles/net/SettingsManagerforWindowsVistaSidebarGadgets.aspx 在以下位置有很好的解释: http : //dotnetslackers.com/articles/net/SettingsManagerforWindowsVistaSidebarGadgets.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM