views:

28

answers:

1

Setup:

I have a combo-box, it's itemsource bound to an ObservableCollection<T> of a custom class, one property is a List<myenum>.

I have an itemscontrol which is databound to the combo-box's selected item List<myenum> property.

The itemscontrol datatemplate creates a list of radiobuttons, each representing the individual enum values in the list.

The Desire:

When I change the value in the combo-box the itemscontrol source is updated. What I want to occur, is if a radio button in the new itemscontrol source is the same as the selected radiobuton in the previous list (before it was updated), this to be checked.

Current Idea:

Asign a Checked event to the radio buttons, which maintains a myenum property in the window class which can be compared against. Make the IsChecked property of the radiobox bind to a converter and compare against the myenum property. To achieve this, I have made the window class extend from IValueConverter, this way the converter function has access to the myenum property.

Issue:

I don't know how to get the IsChecked binding to use the window as the converter. I have tried using relative source in the converter part of the binding, but that doesn't work IsChecked="{Binding Converter={RelativeSource={RelativeSource Self}}}"

Preferred Answers:

Assistance on correcting the binding syntax if it's possible this way.

Ideas of a more appropriate way of achieving what I'd like.

A: 

I also do not know how to use the window as a value converter in xaml. Instead create a standalone value converter class with a public property for the enum type. Next, in the constructor of the window, get a reference to the instance of the value converter and store it in a private member.

XAML:

<local:MyValueConverter x:Key="ConvertSomething" />

Code behind:

private MyValueConverter _myValueConverter;

public Window1()
{
  InitializeComponent();

  _myValueConverter = FindResource("ConvertSomething") as MyValueConverter;
}

private void RadioButton_Checked(object sender, RoutedEventArgs e)
{
    // You can access _myValueConverter here and set its public enum property.    
}
Wallstreet Programmer
This is the route that I took in the end. Had to change the binding to Mode=OneWay as well. But it all works now.
Psytronic