WPF Clickable button under label
I have button. I have expander in button and label above expander in the same button. I can click on button with no problem, but there is problem where I click on label (Nothing happens). How can I make this: When user clicks on label in button, button is being clicked. I want to transfer click event from label to button that contains that label.
<Button>
<Label开发者_JAVA百科 />
<Expander>
</Expander>
</Button>
I want to be able to click button through label.
This change should make your label pass through clicks to the underlying control:
<Button>
<Label IsHitTestVisible="False" />
<Expander>
</Expander>
</Button>
You can bubble up the event using RoutingStrategy.Bubble
. Here is a starter on routed events -> Routed events
You can also force a click event to be triggered for the button that the label is inside of by placing the following code in the eventhandler of the label.
((Button)label1.Parent).RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
精彩评论