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

一世执手 提交于 2019-12-10 22:49:18

问题


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. Possible?


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/7266875/how-to-localize-toggleswitch-on-windows-phone-7-localizing-silverlight-toolkit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!