5

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

kthompson
  • 803
  • 6
  • 16

1 Answers1

7

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);
Ana Betts
  • 73,868
  • 16
  • 141
  • 209
  • How would it know the type of 'ViewModel' ? – fahadash Jul 25 '14 at 01:30
  • 7
    It just knows, deep down in its heart, when the time is right to ViewModel – Ana Betts Jul 25 '14 at 03:34
  • Ok, I guess I found it myself. Your code sample in your answer implies that there should be a property called ViewModel in the View. Not sure how BindTo will be seen by MVVM fanatics – fahadash Jul 25 '14 at 07:34
  • @fahadash you can write the same thing in Xaml with a Converter, but I think it's a nit at best. Perhaps the power is when you move the code to non XAML platforms. – kenny Aug 09 '14 at 13:56