First, your view should implement IViewFor<YourViewModel>
interface and then
this.Bind(ViewModel, vm => vm.PropertyToBind, x => comboBox.SelectedValue, comboBox.Events().SelectedValueChanged)
EDIT:
I have create a demo project:
using System;
using System.Reactive.Linq;
using System.Windows.Forms;
using ReactiveUI;
namespace WindowsFormsApplication
{
public partial class Form1 : Form, IViewFor<MyViewModel>
{
public Form1()
{
InitializeComponent();
ViewModel = new MyViewModel();
comboBox1.DataSource = ViewModel.Items;
var selectionChanged = Observable.FromEvent<EventHandler, EventArgs>(
h => (_, e) => h(e),
ev => comboBox1.SelectedIndexChanged += ev,
ev => comboBox1.SelectedIndexChanged += ev);
this.Bind(ViewModel, vm => vm.SelectedItem, x => x.comboBox1.SelectedItem, selectionChanged);
}
public MyViewModel ViewModel { get; set; }
object IViewFor.ViewModel
{
get { return ViewModel; }
set { ViewModel = (MyViewModel)value; }
}
}
public class MyItem
{
private readonly string _text;
public MyItem(string text)
{
_text = text;
}
public override string ToString()
{
return _text;
}
}
public class MyViewModel : ReactiveObject
{
private MyItem _selectedItem;
public MyViewModel()
{
Items = new ReactiveList<MyItem> {new MyItem("test1"), new MyItem("test2")};
}
public MyItem SelectedItem
{
get { return _selectedItem; }
set { this.RaiseAndSetIfChanged(ref _selectedItem, value); }
}
public ReactiveList<MyItem> Items { get; private set; }
}
}