Silverlight 4 MVVM 应用程序,由用户编辑 resx,仅 Blend?

发布于 2024-10-16 02:10:24 字数 389 浏览 4 评论 0原文

在 Silverlight 4 应用程序中,我们的用户群需要为我们定义他们想要在按钮、标签、各种屏幕文本等上显示的内容。我了解资源文件的方法,但我想知道什么时候想要提供这种内容控制权让用户定义资源文件中的文本,让他们能够查看对 XAML 页面的更改的最佳方式是什么?他们需要安装 Blend 吗?

我依稀记得在制作 WinForms 应用程序时,有一次我将实际的 winform 交给了用户,他们使用某种可视化设计器来编辑按钮文本、标签等,然后将这些更改保存到资源文件中。

我们的应用程序是 MVVM,因此 XAML 中的每个项目都将绑定到其视图模型中的一个属性,然后该属性将从资源文件中加载条目。

如果有办法让用户更新 resx 文件的内容,同时直观地查看其更改,请告诉我。

预先非常感谢您的帮助。

In a Silverlight 4 app, our user base needs to define for us what content they want on buttons, labels, various screen text, etc. I understand the methods of resource files, but what i'm wondering is when wanting to give that kind of control to the users to define the text in the resource file, what is the best way to let them do that in a way that they can view their changes to the XAML pages? Do they need to have Blend installed?

I vaguely remember when doing a WinForms app, at one point I handed off to the users the actual winform, and they used some sort of visual designer to edit button text, labels, etc., and those changes were then saved to the resource file.

Our app is MVVM, so each item in the XAML would bind to a property in its view model, and that property would then load the entry from the resource file.

If there is a way to let the user update the contents of the resx file while visually reviewing their changes please let me know.

Thanks very much in advance for any assistance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

灯角 2024-10-23 02:10:24

我过去所做的是为资源(resx)文件创建一个专用程序集。默认情况下,它们“嵌入”到程序集中。诀窍是将 resx 文件上的属性更改为不嵌入 (False)。这样,这些文件就是单独的 resx xml 文件,必须与程序集一起使用(并且位于正在运行的应用程序的同一 /bin 目录中)。这是您在一些带有 /en-US/ 和其他资源的 /bin 目录中看到的内容。过去,我创建了一个简单的 GUI,让用户能够编辑这些写回磁盘的 resx 文件。我不熟悉 Silverlight 所需的此类权限的内部工作原理,但我猜想在最坏的情况下,编辑后的 ​​resx 文件只会上传到服务器,在下次应用程序重新启动或类似情况时下载新副本。

现在,当我说“过去”时,那是2003年的事了。最近,由于我无法修改现有程序集,我不得不使用 ResXResourceReader 手动执行此操作。

一些示例代码(从内存中编写,完全未经测试):

using (var reader = new ResXResourceReader("[path-to-bin]/MyResources.resx"))
{
  var value = reader["My_key_in_the_resx_file"].ToString;
}

请注意,通过走这条路线,您确实可以访问其他类型的资源,例如二进制文件和嵌入到 resx 文件中的文件。

最后,注意你的编码格式。一些海外编辑器使用UTF16。因此可能需要使用通用的 Unicode 转换器。

另请注意,如果您想使用自己的编写器来通过代码更新 resx 文件,则有一个 ResXResourceWriter 类。

What I have done in the past is to have a dedicated assembly for Resources (resx) files. By default, they are "embedded" into the assembly. The trick is to change the property on the resx file to NOT be embedded (False). This way, the files are separate resx xml files that must go with the assembly (and live in the same /bin directory of the running application). This is what you see in some /bin directories with the /en-US/ and other resources. In the past, I have created a simply GUI for users to be able to edit these resx files that gets written back to disk. I am not familiar with Silverlight's inner workings for this type of permissions needed, but I would guess at worse case the edited resx files just get uploaded to a server where a new copy is downloaded on next app restart or alike.

Now, when I said "in the past", that was back in 2003 days. Recently I had to do this manually using the ResXResourceReader because of an existing assembly I could not modify.

Some example code (writing it from memory, completely untested):

using (var reader = new ResXResourceReader("[path-to-bin]/MyResources.resx"))
{
  var value = reader["My_key_in_the_resx_file"].ToString;
}

Do note that by going this route, you do have access to other types of resources such as binary and files embedded int he resx files.

Lastly, watch your encoding formats. Some over-seas editors use UTF16. So going with a common Unicode converter may be needed.

Also note there is a ResXResourceWriter class, should you want to roll your own writers for updating the resx files through code.

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