Tôi biết câu hỏi này khá cũ, nhưng tôi nghĩ rằng câu trả lời này có thể hữu ích vì không cần phải biên dịch lại mã kiểm soát.
Chúng tôi có thể liên kết Content
với thuộc tính IsChecked
và sử dụng Converter
trả về chuỗi tùy chỉnh của chúng tôi.
Đây là những gì tôi đã làm cho dự án của tôi:
<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}}"/>
nơi SwitchOnOffConverter
là này một:
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();
}
}
Không thực sự là câu trả lời tôi muốn nhưng tôi thấy không có thay thế trừ văn bản nút chuyển đổi của riêng tôi . –