WPF - 视图转换后装饰器保持在原始位置
我定义了一个控件模板,称之为 myVal,用于验证 - 然后在样式定位文本框中使用它,其中 Validation.ErrorTemplate 设置为
现在假设视图中有许多这样的文本框,并且使用 TranslateTransform 和 BeginAnimation 进行滑动。
结果是,ErrorTemplate 中使用的装饰器在视图转换时不会跟随文本框的位置 - 相反,它们会停留在起始位置。但是,一旦我设置焦点或鼠标移动等事件,装饰器就会相对于文本框正确地重新定位自己。
如何让装饰器在变换后显示在正确的位置而不需要改变焦点?有没有办法将验证延迟到转换之后...或者动画完成后如何“重新验证”属性?我在某处读到过有关调用 invalidatevisual 的内容,但不知道如何做到这一点。非常感谢任何帮助。
干杯
I have a control template defined, call it myVal, that is used for validation - this is then used for example in a Style targeting textbox where its Validation.ErrorTemplate is set as
Now say there are a number of such textboxes that sit in a view and that this slides in using TranslateTransform and BeginAnimation.
The result is that the adorner used in the ErrorTemplate doesn't follow the position of the textboxes as the view transitions - instead these stay in the starting position. However, the adorners reposition themselves correctly in relation to the textboxes as soon as I set focus or events such as mouse move.
How can I get the adorners to show in the correct position after the transformation without having to change the focus? Is there a way of delaying the validation until after the transition...or how can I "revalidate" the properties once the animation has finished? I read somewhere about calling invalidatevisual but can't see how I'd do that. Any help is much appreciated.
Cheers
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
两个想法:
尝试在文本框或文本框组周围添加 AdornerDecorator。这将告诉 WPF 为渲染装饰器添加另一个层。添加一个“更靠近”文本框的图层可能会有所帮助。
如果你想告诉装饰层重新渲染自身,那么你可以使用类似以下代码的内容:
Two ideas:
Try adding an AdornerDecorator around the textbox, or around the group of textboxes. This will tell WPF to add another layer for rending adorners. Adding a layer "closer" to the textboxes might help.
If you want to tell the adorner layer to re-render itself, then you can use something like the following code: