First add Localized Resource for our new On and Off string values:
Next step create 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;
- }
- }
- <Application.Resources>
- <local:BoolToSwitchConverter x:Key="Switch" />
- </Application.Resources>
- <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>
"Maybe" that issue was fixed: http://silverlight.codeplex.com/workitem/10164
ReplyDeleteNot sure if fix is already released or if you have to compile WPToolKit by yourself.
I guess your solution works but in my view "On".Equals(value) looks strange ...
A good blog always comes-up with new and exciting information and while reading I have feel that this blog is really have all those quality that qualify a blog to be a one. GDPR toolkit
ReplyDelete