wpf radio-button master-detail

Radiobutton wpf vinculante



radio-button master-detail (1)

Tengo una aplicación wpf de detalles maestros. El "maestro" es una cuadrícula de datos, y "detalle" son dos botones de opción. Según la selección de fila, los botones de opción se verifican en la sección "detalles".

Estoy vinculando mi botón de Radio de la siguiente manera usando un convertidor inttoboolean. xaml:

<StackPanel Margin="2"> <RadioButton Margin="0,0,0,5" Content="In Detail" IsChecked="{Binding Path=itemselect.OutputType, Converter ={StaticResource radtointOTSB}, ConverterParameter= 0}"/> <RadioButton Content="In Breif" IsChecked="{Binding Path=itemselect.OutputType, Converter ={StaticResource radtointOTSB}, ConverterParameter= 1}"/> </StackPanel>

En el modelo de vista:

public class radtointOTSB : IValueConverter { object IValueConverter.Convert(object value, Type targetType, object parameter, CultureInfo culture) { int OTint = Convert.ToInt32(value); if (OTint == int.Parse(parameter.ToString())) return true; else return false; } object IValueConverter.ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { return parameter; } }

Mi implementación funciona bien para las primeras selecciones en DataGrid. Y, de repente, ninguno de mis botones de opción está seleccionado.

No tengo idea de por qué sucede, cualquier sugerencia es bienvenida.

Gracias por adelantado.


Busque problemas al vincular múltiples RadioButtons: hay suficientes quejas por ahí. Básicamente, el enlace no recibirá el valor de False porque no se pasa a la Propiedad de Dependencia ... etc.

Intenta usar la siguiente clase en lugar del RadioButton normal, vincúlalo a IsCheckedExt, ya que obliga a actualizar el valor IsChecked de la casilla de verificación.

public class RadioButtonExtended : RadioButton { public static readonly DependencyProperty IsCheckedExtProperty = DependencyProperty.Register("IsCheckedExt", typeof(bool?), typeof(RadioButtonExtended), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.Journal | FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, IsCheckedRealChanged)); private static bool _isChanging; public RadioButtonExtended () { Checked += RadioButtonExtendedChecked; Unchecked += RadioButtonExtendedUnchecked; } public bool? IsCheckedExt { get { return (bool?)GetValue(IsCheckedExtProperty); } set { SetValue(IsCheckedExtProperty, value); } } public static void IsCheckedRealChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { _isChanging = true; ((RadioButtonExtended)d).IsChecked = (bool)e.NewValue; _isChanging = false; } private void RadioButtonExtendedChecked(object sender, RoutedEventArgs e) { if (!_isChanging) IsCheckedExt = true; } private void RadioButtonExtendedUnchecked(object sender, RoutedEventArgs e) { if (!_isChanging) IsCheckedExt = false; } }