在视图模型文本框caretIndex属性 [英] TextBox CaretIndex property in ViewModel

查看:431
本文介绍了在视图模型文本框caretIndex属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能获取/设置通过在视图绑定定义在WPF中视图模型一个TextBox控件的caretIndex属性的值?

Is it possible to get/set the value of CaretIndex property of a TextBox control in viewmodel in wpf via Binding defined in view?

感谢

推荐答案

这里的问题是如何获得文本框 CaretIndex code>通过视图模型控制。
如果意图通过直接绑定到视图模型其不可能得到它。正如我张贴在previous回答了一个CLR属性而不是一个依赖项属性。

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.

我们能做些什么?

对于最好的办法是要遵循的步骤:

The best solution for that is to follow the steps:


  1. 在通过单独的类控制定义附加属性。

  2. 定义的视图模型的属性和附加属性绑定到一个在视图模型

  3. 根据接收到新的值更新的附加属性更改事件的回调控件的属性。

在这种情况下,我们仍然认为从模型中分离出来。

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

我希望我的回答可以帮助你!

I hope my answer helps you!

这篇关于在视图模型文本框caretIndex属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆