开发者

WPF Clickable button under label

开发者 https://www.devze.com 2023-01-20 22:44 出处:网络
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 ma

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));
0

精彩评论

暂无评论...
验证码 换一张
取 消