按钮内的WPF按钮单击问题 [英] WPF Button inside a button Click issue

查看:174
本文介绍了按钮内的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.

推荐答案

将内部按钮的单击事件标记为像<$ c $一样处理c> 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按钮单击问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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