2

Currently I have a RadioButton that is bound to a generic type... TestObject<T>

In this object, I have a property called Value which can be either 1 or 0. I have a property called MyList which is a Dictionary<T,String> which holds the following values:

   INT          String
    0            "This is the first option"
    1            "This is the second option"

What I am having trouble doing binding the RadioButton to MyList. Currently I have IsCheck ed bound to Value (with a converter to return true/false). My biggest issue is the dictionary and how to bind it to the RadioButton control so I can see 2 RadioButton options on the screen.

Any ideas?

Nerd in Training
  • 2,098
  • 1
  • 22
  • 44

2 Answers2

1

Why dont you use a List of KeyValuePairs or Tuples instead of a Dictionary?

Then you could use the ItemsControl, put the RadioButton in your DataTemplate and bind the ItemsSource to you List of KeyValuePairs.

Florian Gl
  • 5,984
  • 2
  • 17
  • 30
0

Try filling the radio buttons during runtime.

Here's an example using WPF:

    private RadioButton CreateRadioButton(RadioButton rb1, string content, Thickness margin, string name)
    {
        //private RadioButton CreateRadioButton(RadioButton rb1, string content, Thickness margin, string name)
        // We create the objects and then get their properties. We can easily fill a list.
        //MessageBox.Show(rb1.ToString());

        Type type1 = rb1.GetType();
        RadioButton instance = (RadioButton)Activator.CreateInstance(type1);

        //MessageBox.Show(instance.ToString()); // Should be the radiobutton type.
        PropertyInfo Content = instance.GetType().GetProperty("Content", BindingFlags.Public | BindingFlags.Instance);
        PropertyInfo Margin = instance.GetType().GetProperty("Margin", BindingFlags.Public | BindingFlags.Instance);
        PropertyInfo Name = instance.GetType().GetProperty("Name", BindingFlags.Public | BindingFlags.Instance);
        // This is how we set properties in WPF via late-binding.
        this.SetProperty<RadioButton, String>(Content, instance, content);
        this.SetProperty<RadioButton, Thickness>(Margin, instance, margin);
        this.SetProperty<RadioButton, String>(Name, instance, name);

        return instance;
        //PropertyInfo prop = type.GetProperties(rb1);
    }

    // Note: You are going to want to create a List<RadioButton>
devinbost
  • 4,658
  • 2
  • 44
  • 57