Note that there are some explanatory texts on larger screens.

plurals
  1. POSet of RadioButton controls setting a WPF DependencyProperty via Binding
    primarykey
    data
    text
    <p>I am tring to create a simple UserControl that contains a set of RadioButtons and then sets a single DependencyProperty to a char value (each RadioButton has a unique char value associated with it). I'm taking my cue from this article <a href="http://wpftutorial.net/RadioButton.html" rel="nofollow">http://wpftutorial.net/RadioButton.html</a> which seemed to be an elegant solution, but I can't get it to work. Checking one of the RadioButtons does not change the Property. Neither of the ValueConverter's methods are ever called. There are no compile-time errors or binding errors at run-time. What am I missing?</p> <p>Here is my XAML:</p> <pre><code>&lt;UserControl x:Class="TestClientWpf.OrderTypePicker" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:TestClientWpf="clr-namespace:TestClientWpf"&gt; &lt;WrapPanel&gt; &lt;WrapPanel.Resources&gt; &lt;TestClientWpf:CharMatchToBooleanConverter x:Key="converter" /&gt; &lt;/WrapPanel.Resources&gt; &lt;RadioButton IsChecked="{Binding Path=OrderType, Mode=TwoWay, Converter={StaticResource converter}, ConverterParameter=1}"&gt;Type 1&lt;/RadioButton&gt; &lt;RadioButton IsChecked="{Binding Path=OrderType, Mode=TwoWay, Converter={StaticResource converter}, ConverterParameter=2}"&gt;Type 2&lt;/RadioButton&gt; &lt;RadioButton IsChecked="{Binding Path=OrderType, Mode=TwoWay, Converter={StaticResource converter}, ConverterParameter=3}"&gt;Type 3&lt;/RadioButton&gt; &lt;/WrapPanel&gt; &lt;/UserControl&gt; </code></pre> <p>My code behind:</p> <pre><code>public partial class OrderTypePicker { public static readonly DependencyProperty OrderTypeProperty = DependencyProperty.Register("OrderType", typeof(char), typeof(OrderTypePicker), new FrameworkPropertyMetadata('1')); public char OrderType { get { return (char)GetValue(OrderTypeProperty); } set { SetValue(OrderTypeProperty, value); } } public OrderTypePicker() { InitializeComponent(); } } </code></pre> <p>My ValueConverter:</p> <pre><code>public class CharMatchToBooleanConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (value == null || parameter == null) return false; string checkValue = value.ToString(); string targetValue = parameter.ToString(); return checkValue.Equals(targetValue, StringComparison.InvariantCultureIgnoreCase); } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { if (value == null || parameter == null) return null; bool useValue = (bool)value; string targetValue = parameter.ToString(); return useValue ? char.Parse(targetValue) : (char?) null; } </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
 

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