Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between ReactiveUI's BindTo and ToProperty methods?

ToProperty() appears to be used for read-only properties that are based on observables but when would I want to use BindTo()?

like image 340
MrUnleaded Avatar asked Jul 23 '14 17:07

MrUnleaded


1 Answers

ToProperty is for ViewModels, whereas BindTo is a bit more flexible and is intended to be used in the View layer of your applications. For example (this specific use-case isn't actually a best practice, but it's a good example):

this.WhenAny(x => x.ViewModel.IsTextEnabled)
    .Select(x => x ? Visibility.Visible : Visibility.Collapsed)
    .BindTo(this, x => x.TextBox.Visibility);
like image 70
Ana Betts Avatar answered Oct 12 '22 23:10

Ana Betts