How to configure wp7 toolkit ToggleSwitch

I have a WP7 toolkit and I use a toggle switch.

It currently displays "On." or off.

I know that you can customize it with a content template, and the sample code provided with takeit shows this, but I cannot find a way to add something else to On / Off.

I want to show Yes and No.

+5
source share
4 answers

Hum, since the lines "On" and "Off" come from the converter installed in the private method in the source code, I do not see many alternatives: http://silverlight.codeplex.com/SourceControl/changeset/view/55144#1325068

Change the source code to have something more flexible?

+2

, , IsChecked. , :

<toolkit:ToggleSwtich IsChecked="{Binding Completed}" Content="{Binding Completed, Converter={StaticResource YesNoConverter}" />
+3

: No , "", "":

private void ToggleSwitch_Checked(object sender, RoutedEventArgs e)
    {
        togButton.Content = "Yes";
    }

    private void ToggleSwitch_Unchecked(object sender, RoutedEventArgs e)
    {
        togButton.Content = "No";

    }
+2

, , , , .

Content IsChecked Converter, .

, :

<toolkit:ToggleSwitch SwitchForeground="{StaticResource PhoneAccentBrush}"
                      Grid.Row="3" Grid.Column="1" 
                      Header="{Binding Path=LocalizedResources.MyLabel, Source={StaticResource LocalizedStrings}}"
                      Content="{Binding IsChecked, Converter={StaticResource SwitchOnOffConverter}, RelativeSource={RelativeSource Self}}"/>

SwitchOnOffConverter - :

public class SwitchOnOffConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {           
        return ((bool) value) ? AppResources.YesText : AppResources.NoText;
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        throw new NotSupportedException();
    }
}
+2

All Articles