Lets say I have this enum
public enum LogType
{
None = 0,
File = 1,
Folder = 2
}
I have this ComboBox in view
<ComboBox Name="CustomLogLogType" FontSize="10"
MinHeight="20" Height="20" SelectedItem="{Binding LogType}">
Then a ViewModel like so
public class CustomLogRuleItemViewModel : ReactiveObject
{
[Reactive]
public LogType LogType { get; set; } = LogType.File;
public List<LogType> LogTypes => Enum.GetValues(typeof(LogType)).Cast<LogType>().Where(_ => _ != LogType.None).ToList();
}
Then in code behind for the view
public partial class CustomLogRuleItemView : ReactiveUserControl<CustomLogRuleItemViewModel>
{
public CustomLogRuleItemView()
{
InitializeComponent();
this.ViewModel = new CustomLogRuleItemViewModel();
this.DataContext = this.ViewModel;
//The below works
//CustomLogLogType.ItemsSource = this.ViewModel.LogTypes;
this.WhenActivated(
disposables =>
{
//If I use below it will error with exception
this.OneWayBind(this.ViewModel,
_ => _.LogTypes, _ => _.CustomLogLogType.ItemsSource)
.DisposeWith(disposables);
});
}
}
Basically if I bind with below it works
CustomLogLogType.ItemsSource = this.ViewModel.LogTypes;
But if i try to use ReactiveUI to do the binding as in below
this.OneWayBind(this.ViewModel,
_ => _.LogTypes, _ => _.CustomLogLogType.ItemsSource)
.DisposeWith(disposables);
I get an exception stating that LogType on ReactiveUI.IViewFor violates the constraint of type 'T'. Unsure why I would be getting something arguing about IViewFor as that just has to do with the ViewModel implementation for view.