Skip to content

Instantly share code, notes, and snippets.

@anaisbetts
Created August 21, 2012 09:19
Show Gist options
  • Select an option

  • Save anaisbetts/3413836 to your computer and use it in GitHub Desktop.

Select an option

Save anaisbetts/3413836 to your computer and use it in GitHub Desktop.
RxUI 4.0 View Bindings
public sealed partial class MainPage : Page, IViewForViewModel<MainPageViewModel>
{
public MainPage()
{
this.InitializeComponent();
// Wired up by convention, looks for a control on MainPage named Test and wires it up
this.Bind(ViewModel, x => x.Test);
// Same deal, looks for a control named FooTest
this.OneWayBind(ViewModel, x => x.FooTest);
}
object IViewForViewModel.ViewModel
{
get { return ViewModel; }
set { ViewModel = (MainPageViewModel)value; }
}
public MainPageViewModel ViewModel { get; set; }
}
public class MainPageViewModel : ReactiveObject
{
string _Test;
public string Test {
get { return _Test; }
set { this.RaiseAndSetIfChanged(x => x.Test, value); }
}
ObservableAsPropertyHelper<string> _FooTest;
public string FooTest {
get { return _FooTest.Value; }
}
public MainPageViewModel()
{
this.WhenAny(x => x.Test, x => x.Value)
.Select(x => "Foo" + x ?? "")
.Do(x => Debug.WriteLine(x))
.ToProperty(this, x => x.FooTest);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment