Silverlight 4 MVVM app, resx editing by user, Blend only?

366 Views Asked by At

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.

1

There are 1 best solutions below

0
On

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.