In XAML, I have a set of radio buttons as:
<RadioButton Width="25"
Height="25"
Foreground="Blue"
IsChecked="{Binding ??????, Converter={StaticResource StrokeTypeConverter}, ConverterParameter="Ellipse}"
GroupName="StrokeTypeGroup" />
The purpose of each radio button of the "StylusTypeGroup" is to allow selection of either an "Ellipse" , "Line" , or "Rectangle" custom stroke, etc...
Further down in the XAML, I have a behavior tied to an InkCanvas like:
<InkCanvas x:Name="MainInkCanvas"
Grid.Column="1"
Grid.Row="1"
Background="Transparent"
DefaultDrawingAttributes="{Binding CurrentPen.Pen}"
EditingMode="{Binding EditingMode}">
<i:Interaction.Behaviors>
<b:MainInkCanvasBehavior CustomStrokeType = "{Binding???????}" />
</i:Interaction.Behaviors>
Is there any way using just the XAML code, to bind the result of checking any one (of multiple) radio buttons directly to the CustomStrokeType dependency property of the MainInkCanvasBehavior behavior? Or am I forced to bind to a property on the viewmodel (as kind of a holding property)?
TIA
The least amount of effort is to create a new property, CheckedRadioButtonID, bind that to your CustomStrokeType and use an IValueConverter to take an int and return a Stroke. The key is that when the radio button is clicked, you also want to raise an INotifyPropertyEvent for the CheckedRadioButtonID.
public int CheckedRadioButtonID
{
get
{
if(IsAChecked) return 1;
/// ...
}
// returns 1,2,3... (number of radio buttons you have)
// Implements INotifyPropertyChanged
}
public bool IsAChecked
{
set
{
// when this is set... also raise CheckedRadioButtonID property changed
}
}
In XAML bind to CheckedRadioButtonID and have a IValueConverter take an int and return a Stroke.
If you really want to use a MultiValueConverter it would like like this
<b:MainInkCanvasBehavior >
<b:MainInkCanvasBehavior.CustomStrokeType>
<MultiBinding Converter="{StaticResource MultiValueConverterThatReturnsStroke}">
<Binding ElementName="RadioButton1" Path="IsChecked"></Binding>
<Binding ElementName="RadioButton2" Path="IsChecked"></Binding>
</MultiBinding>
</b:MainInkCanvasBehavior.CustomStrokeType>
</b:MainInkCanvasBehavior>