TextBox CaretIndex property in ViewModel

笑着哭i 提交于 2019-12-04 16:54:41

You can not bind the property CaretIndex since it is not a DependencyProperty. It is a CLR property that does not accept binding.

The issue here is how to get the CaretIndex of the TextBox control via the view model. If you intent to get it directly by binding to the view model its impossible. As I posted in the previous answer its a CLR property and not a dependency property.

What can we do?

The best solution for that is to follow the steps:

  1. Define attached property on the control via separate class.
  2. Define a property in the view model and bind the attached property to the one in the view-model
  3. Update the control property in the callback of the attached property changed event according to the new value received.

In this case, we still separate the view from the model.

I hope my answer helps you!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!