2
votes

I am converting a silverlight XAML/C# app to Metro. For C# code there is no problem. For XAML, from what I read there is new support for XAML to simplify the process. However, I hope to reuse the same resx files so I prefer the old silverlight mechanism for XAML, i.e. Markup Extension or Binding. I just tried MarkupExtension but it doesn't seem to support. How do I convert the resource binding. Note my goal is to reuse the name-value pairs in the resource files so I won't be able to use the new Metro binding mechanism.

Any suggestion?

Something like this in silverlight:

XAML:

<sdk:TabItem Header="{Binding Path=Resource.charts, Source={StaticResource LocalizedStrings}}"/>

LocalizedStrings.cs

    public partial class LocalizedStrings
    {

        private static Resources.Resource resource = new Resources.Resource();

        public Resources.Resource Resource { get { return resource; } }
    }

New Metro style localization that I won't be able to use due to old code reuse:

<TextBlock x:Uid="HelloWorld" />
2

2 Answers

1
votes

I end up writing a converter to change all my resource files. "somekey" from the Silverlight resource file is converted to "somekey.Content". This will take care of some UI elements automatically with a Content property, such as Button.

0
votes

If you don't want to change the name-value pairs, you'll have to use the ResourceLoader class to access the .resw files.

var resourceLoader = new ResourceLoader();
// access a given name key
var var someValue = resourceLoader.GetString("someKey");

This means that you'll have to write quite some properties to bind too and alter the XAML to the new bindable properties. So it might be worth considering changing to the new Metro localization after all.

A complete example on localization can be found on the win8 dev center.