按钮内的WPF按钮单击问题

编程入门 行业动态 更新时间:2024-10-25 10:28:46
本文介绍了按钮内的WPF按钮单击问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在我的WPF项目中有以下结构(非常简化): $ b

I have the following structure (very simplified) in my WPF project:

Button newProduct = new Button(); Grid newGrid = new Grid(); Button modify = new Button(); Button remove = new Button(); newGrid.Children.add(modify); newGrid.Children.add(remove); newProduct.Content = newGrid;

每个按钮都有其自己的点击事件。在按钮中也有文本块。 NewProduct突出显示其内容,修改textblocks信息并删除主视图中的按钮。

Each button has its own click event. There are textblocks inside the button as well. NewProduct highlights its content, modify changes the textblocks info and remove deletes the main button from the view.

我的问题是,无论何时点击较大的按钮(修改,删除),更大的clickProduct的点击事件也会触发。 newProduct点击事件根据需要改变其大小,当点击修改或移除时,我不需要它做任何事情。

My problem is that whenever I click one of the buttons inside the bigger one(modify, remove), the click event from the bigger one, newProduct, also fires. The newProduct click event changes its size according to what is needed and I don't need it to do anything when modify or remove is clicked.

我的问题是。我怎么能做到这一点,如果点击主按钮中的一个按钮,只有他们各自的点击事件被触发,而不是主要的按钮?

My question is. How can I make that if one of the buttons inside of the main button is clicked, only their respective click event is fired, and not the one from the main one?

有没有办法告诉newProduct忽略它的点击事件,当鼠标是其中一个孩子?

Is there a way to tell newProduct to ignore its click event when the mouse is over one of its childs?

谢谢,如果这已被回答,我提供道歉,

Thank you and I offer my apologies if this has been answered, I searched a lot and didn't find what I needed.

推荐答案

将内部按钮的单击事件标记为像 e.Handled = true; 在您的处理程序结束时。

Mark inner button's click event as handled like e.Handled = true; at the end of your handlers.

您内在的Button的Click处理程序:

Your inner Button's Click handler :

private void Button_Click(object sender, RoutedEventArgs e) { // some logic e.Handled = true; }

更多推荐

按钮内的WPF按钮单击问题

本文发布于:2023-11-27 15:53:07,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:按钮   单击   WPF

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!