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>