I've seen lots of solutions for binding a ReactiveList to a ComboBox control in WPF such that the control displays the enum items' descriptions. All of these solutions use a standard TypeConverter and binding in the XAML, but I'm using ReactiveUI, so I want to do the bindings in the code behind. Without any sort of conversion, I get the raw enum values as strings rather than their descriptions, so at least I know the binding is working properly, but I haven't figured out the conversion.
I'm pretty sure that I need to use an IBindingTypeConverter (and register it using Splat), but I can't seem to find the right combination of toType and fromType in my converter to make this happen. I tried the following with partial success:
public class MyEnumToStringConverter : IBindingTypeConverter
{
public int GetAffinityForObjects(Type fromType, Type toType)
{
if (fromType == tyepof(ReactiveList<MyEnumType>))
{
return 100;
}
return 0;
}
public bool TryConvert(object from, Type toType, object conversionHint, out object result)
{
...
}
}
In the debugger, GetAffinityForObjects() gets hit and returns 100 during the call to bind the ComboBox's ItemsSource, but TryConvert never gets called.
Can anyone provide a nice example for doing this the Right Way in ReactiveUI?