static void toggleSwitch_Toggled(object sender, RoutedEventArgs e) { ToggleSwitch Switch = (sender as ToggleSwitch); if (Switch != null) { ICommand command = Switch.GetValue(CommandProperty) as ICommand; if (command != null) { command.Execute(Switch.IsOn); } } }