I've managed to do what I was hoping to achieve by using a converter parameter. Checking one of the three checkboxes, updates the value of SelectedIndex. Entering the value of SelectedIndex into the textbox will check the correct checkbox and uncheck the others.
<StackPanel Orientation="Horizontal" Height="70">
<local:ButtonTest SelectedIndex="{Binding SelectedIndex}" />
<TextBox Width="100" Text="{Binding SelectedIndex, Mode=TwoWay}" />
<Button Content="Update UserControl" />
</StackPanel>
<UserControl.Resources>
<cnvtr:EquatorToBoolConverter x:Key="EquatorToBoolConverter" />
</UserControl.Resources>
<StackPanel Orientation="Horizontal">
<CheckBox Content="One"
IsChecked="{Binding SelectedIndex, Converter={StaticResource EquatorToBoolConverter}, ConverterParameter=1}"/>
<CheckBox Content="Two"
IsChecked="{Binding SelectedIndex, Converter={StaticResource EquatorToBoolConverter}, ConverterParameter=2}" />
<CheckBox Content="Three"
IsChecked="{Binding SelectedIndex, Converter={StaticResource EquatorToBoolConverter}, ConverterParameter=3}" />
<TextBlock Margin="10"
Padding="10"
FontWeight="Black"
Text="{Binding SelectedIndex}"/>
</StackPanel>
public partial class ButtonTest : UserControl
{
public ButtonTest()
{
InitializeComponent();
}
public int SelectedIndex
{
get => (int)GetValue(SelectedIndexProperty);
set => SetValue(SelectedIndexProperty, value);
}
public static readonly DependencyProperty SelectedIndexProperty =
DependencyProperty.Register("SelectedIndex", typeof(int), typeof(ButtonTest), new PropertyMetadata(0));
}
class EquatorToBoolConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return (value.ToString() == parameter.ToString());
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
var actualValue = (bool)value;
var param = int.Parse(parameter.ToString());
return actualValue ? param : 0;
}
}
private int _selectedIndex;
public int SelectedIndex
{
get => _selectedIndex;
set
{
if (_selectedIndex != value)
{
_selectedIndex = value;
OnPropertyChanged();
}
}
}