如何在设置为false的子项上将IsHitTestVisible设置为True? [英] How can you set IsHitTestVisible to True on a child of something where it's set to false?

查看:200
本文介绍了如何在设置为false的子项上将IsHitTestVisible设置为True?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一条消息在边框内,并显示在MDI客户区的前面.因为这只是一条消息,所以将它的IsHitTestVisible设置为false.为方便起见,我在其中还包含一个按钮,因此用户只需单击该按钮即可开始新图.

I have a message which is within a border and is displayed in front of a MDI client area. Because it's just a message, I set it's IsHitTestVisible to false. For convenience, I've also included a button within it so the user can simply click the button to start a new diagram.

但是,由于边框的IsHitTestVisible设置为False,因此边框会缩短按钮的True值,因此用户无法单击按钮.

However, because the border has its IsHitTestVisible set to False, it shorts out the True value of the button so the user can't click on the button.

也就是说,如何使控件对鼠标不可见,同时仍允许其子级之一接收鼠标事件?

That said, how can you make a control invisible to the mouse, while still allowing one of its children to receive mouse events?

以下是屏幕截图:

我们希望带有文本的蓝色区域不被点击测试可见,但是我们希望按钮仍然能够被按下.有什么想法吗? (是的,我已经知道将两个项目堆叠在一个网格中,但这与布局混乱了.

We want the blue area with text to be hit-test invisible, but we want the button to still be able to be pressed. Thoughts? (And yes, I already know about stacking the two items in a grid, but that messes with the layout.

推荐答案

好吧,看起来问题无法按要求解决,因此看起来我们不得不恢复到分层方法.在这种情况下,为了补偿文本更改,您必须将按钮的垂直对齐方式设置为底部",并确保边框的底部边缘或TextBlock的底部空白处有额外的填充),以确保标签始终浮在标签上方.按钮.您可以使用相同的原则来管理两者的边距/边距.

Ok, doesn't look like the question can be solved as asked, and therefore it looks like we have to revert to the layered method. In that case, to compensate for text changes, you have to set the vertical alignment of the button to Bottom, and ensure there's extra padding on the bottom edge of the border or bottom margin on the TextBlock) to ensure the label always floats above the button. You manage the side margins/padding for both using the same principles.

这将为我们提供我们所需要的东西,但是看起来很麻烦.再次,我希望可以通过某种方式用强制"指定IsHitTestVisible(或就此而言为IsEnabled),以某种方式将其重新建立为行为的所有者(及以下).一个人可以做梦.直到那时...都是分层!

This will give us what we're after, but just seems pretty cumbersome. Again, I wish there was some way to specify IsHitTestVisible (or IsEnabled for that matter) with a 'Force' somehow that re-establishes them (and below) as the owner of the behaviors. A person can dream. Until then... layers it is!

这篇关于如何在设置为false的子项上将IsHitTestVisible设置为True?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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