不要将光标更改为 TextBox
我试图使 TextBox 对用户来说看起来像 TextBlock (它位于我希望允许重命名的树视图中)。我可以通过应用样式将边框和背景设置为透明并将 IsReadOnly 属性设置为 true 来做到这一点。我唯一的问题是鼠标光标仍然从指针样式更改为编辑(插入符号)样式。有没有一种简单的方法来禁用它(最好在xaml中)?
I am trying to make a TextBox look like a TextBlock to the user (it is in a treeview that I want to allow renaming in). I was able to do this by applying a style to set the border and background to transparent and the IsReadOnly property to true. My only problem is that the mouse cursor still changes from the pointer style to the editing (caret) style. Is there an easy way to disable this (preferably in xaml)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
当然,只需将文本框的
Cursor
属性设置为Arrow
Sure, just set the TextBox's
Cursor
property toArrow
这个怎么样?
How about this?
我不确定是否可以在 XAML 中设置它,但在代码中您应该能够更改
TextBox
的Cursor
属性。或者,如果您创建一个控件模板来完全覆盖TextBox
,您应该能够完全控制光标。希望前者能解决问题。编辑
作为上述内容的扩展,如果您需要处理鼠标悬停在
TextBox
上以确定何时设置Cursor
属性,您可以可以处理TextBox
的MouseEnter
和MouseLeave
事件。I'm not sure if it can be set in XAML, but in code you should be able to change the
Cursor
property of theTextBox
. Alternately, you should be able to have full control over the cursor if you create a control template to overwrite theTextBox
in its entirety. Hopefully the former will do the trick.EDIT
As an extension to the above, if you need to handle the mouse hovering over the
TextBox
to determine when to set theCursor
property, you can handle theTextBox
'sMouseEnter
andMouseLeave
events.