Created
August 21, 2012 09:19
-
-
Save anaisbetts/3413836 to your computer and use it in GitHub Desktop.
RxUI 4.0 View Bindings
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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