Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Use a value converter like this:</p> <pre><code>public class RadioValueConverter : IValueConverter { public int Value { get; set; } public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ((int)value == Value) { return true; } return false; } public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ((bool)value == true) { return Value; } return null; } } </code></pre> <p>In the ConvertBack, clicking a RadioButton will always set a true value, so you should never get to the return null. I don't know of any ways that this would happen at least.</p> <p>Then in your XAML, you can create a converter for each RadioButton:</p> <pre><code>&lt;StackPanel HorizontalAlignment="Left" Name="stackPanel1" VerticalAlignment="Center" Orientation="Horizontal"&gt; &lt;StackPanel.Resources&gt; &lt;loc:RadioValueConverter x:Key="FirstValue" Value="1"/&gt; &lt;loc:RadioValueConverter x:Key="SecondValue" Value="2"/&gt; &lt;loc:RadioValueConverter x:Key="ThirdValue" Value="3"/&gt; &lt;/StackPanel.Resources&gt; &lt;RadioButton Content="Disable" Name="disableRadio" VerticalAlignment="Center" IsChecked="{Binding SelectedIndex, Converter={StaticResource FirstValue}}" /&gt; &lt;RadioButton Content="Enable" Name="enableRadio" VerticalAlignment="Center" Margin="5,0,0,0" IsChecked="{Binding SelectedIndex, Converter={StaticResource SecondValue}}" /&gt; &lt;RadioButton Content="Configure" Name="configureRadio" VerticalAlignment="Center" Margin="5,0,0,0" IsChecked="{Binding SelectedIndex, Converter={StaticResource ThirdValue}}"/&gt; &lt;/StackPanel&gt; </code></pre> <p>This should provide 2-way binding too, so if you change the SelectedIndex elsewhere, the RadioButtons will follow.</p> <p>Also, I forgot to mention before but this code assumes you've set the DataContext of your CommandControl to itself, ie in the constructor:</p> <pre><code> public CommandControl() { InitializeComponent(); DataContext = this; SelectedIndex = 1; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload