开发者

How to localize ToggleSwitch on Windows Phone 7 (localizing Silverlight Toolkit)?

Silverlight Toolkit has a resource file named Resources.resx, which contains "On" and "Off" string states for the switch. But when I have added a corresponding localized resource, Resources.ru-RU.resx, it wasn't picked up by the localization (though the similar approach works for my own resources).

One way to do it is to create my own binding for the ToggleSwitch Content, but I was hoping for a non-coding solution. Poss开发者_运维问答ible?


Localize ToggleSwitch in Silverlight Toolkit can be achived via DataTemplate

    <toolkit:ToggleSwitch x:Name="MySwitch" Header="Localized Switch">  
        <toolkit:ToggleSwitch.ContentTemplate>  
            <DataTemplate>  
                <ContentControl HorizontalAlignment="Left"   
                    Content="{Binding Converter={StaticResource Switch}}"/>  
            </DataTemplate>  
        </toolkit:ToggleSwitch.ContentTemplate>  
    </toolkit:ToggleSwitch>

Declare an ValueConverter:

    public class BoolToSwitchConverter : IValueConverter  
    {  
        private string FalseValue = Resources.Off;  
        private string TrueValue  = Resources.On;  

        public object Convert(object value, Type targetType, object parameter,
              System.Globalization.CultureInfo culture)  
        {  
            if (value == null)  
                return FalseValue;  
            else  
                return ("On".Equals(value)) ? TrueValue : FalseValue;  
        }  

        public object ConvertBack(object value, Type targetType, 
               object parameter, System.Globalization.CultureInfo culture)  
        {  
            return value != null ? value.Equals(TrueValue) : false;  
        }  
    }

More details here.


You need to name your resource file ControlResources.ru-RU.resx , see Andrej Torzen's article on the subject.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜