В моем XAML есть несколько RadioButton ...
<StackPanel>
<RadioButton Name="RadioButton1" GroupName="Buttons" Click="ButtonsChecked" IsChecked="True">One</RadioButton>
<RadioButton Name="RadioButton2" GroupName="Buttons" Click="ButtonsChecked">Two</RadioButton>
<RadioButton Name="RadioButton3" GroupName="Buttons" Click="ButtonsChecked">Three</RadioButton>
</StackPanel>
И я могу обрабатывать их события щелчка в коде Visual Basic. Это работает...
Private Sub ButtonsChecked(ByVal sender As System.Object, _ ByVal e As System.Windows.RoutedEventArgs) Select Case CType(sender, RadioButton).Name Case "RadioButton1" 'Do something one Exit Select Case "RadioButton2" 'Do something two Exit Select Case "RadioButton3" 'Do something three Exit Select End Select End Sub
Но я бы хотел его улучшить. Этот код не работает ...
<StackPanel>
<RadioButton Name="RadioButton1" GroupName="Buttons" Click="ButtonsChecked" Command="one" IsChecked="True">One</RadioButton>
<RadioButton Name="RadioButton2" GroupName="Buttons" Click="ButtonsChecked" Command="two">Two</RadioButton>
<RadioButton Name="RadioButton3" GroupName="Buttons" Click="ButtonsChecked" Command="three">Three</RadioButton>
</StackPanel>
Private Sub ButtonsChecked(ByVal sender As System.Object, _ ByVal e As System.Windows.RoutedEventArgs) Select Case CType(sender, RadioButton).Command Case "one" 'Do something one Exit Select Case "two" 'Do something two Exit Select Case "three" 'Do something three Exit Select End Select End Sub
В моем XAML я получаю синее волнистое подчеркивание атрибутов Command = и этот совет ...
'CommandValueSerializer' ValueSerializer cannot convert from 'System.String'.
В моем VB я получаю зеленое волнистое подчеркивание в строке Select Case, и это предупреждение ...
Runtime errors might occur when converting 'System.Windows.Input.ICommand' to 'String'.
Еще лучше было бы использовать команды типа Enum с полным Intellisense и ошибки компиляции, а не ошибки времени выполнения в случае опечаток. Как я могу это улучшить?