[英]How to be able to have a two line text on Button content WPF ? And be able to click on text and activate Button1_click
The code is shown below. 代码如下所示。 When I try to click on the middle of the button you are actually clicking the TextBlock and not triggering the Button2_click event. 当我尝试单击按钮的中间时,实际上是在单击TextBlock而不触发Button2_click事件。 Only if you click outside of the TextBlock and still inside of the Button it would trigger the event. 仅当您在TextBlock之外单击并且仍在Button内时,它才会触发事件。
What is the right way of having a two line text inside the content of the Button.I'm a new on StackOverFlow so I don't have enough reputation to add a picture. 在Button的内容中包含两行文本的正确方法是什么。我是StackOverFlow的新手,所以我没有足够的声誉来添加图片。 Please some Help with this question. 请对此问题提供一些帮助。 Thanks for the Help in Advance. 我在这里先向您的帮助表示感谢。
<Button Content="" Height="77" HorizontalAlignment="Left" Margin="70,136,0,0" Name="Button2" VerticalAlignment="Top" Width="202" />
<TextBlock TextAlignment="Center" Padding="2" Margin="80,152,0,135" FontSize="16" HorizontalAlignment="Left" Width="181" TextWrapping="NoWrap" Foreground="#FF8787DB" FontWeight="Bold"> Calculate CTR Losses<LineBreak></LineBreak> (From FTD Data)</TextBlock>
Put your TextBlock
inside your button: 将您的TextBlock
放在按钮内:
<Button HorizontalAlignment="Left" Margin="70,136,0,0" Name="Button2" VerticalAlignment="Top">
<TextBlock Padding="2" FontSize="16" TextWrapping="NoWrap" Foreground="#FF8787DB" FontWeight="Bold">
Calculate CTR Losses
<LineBreak />
(From FTD Data)
</TextBlock>
</Button>
This will implicitly set Button.Content
, it's an equivalent of: 这将隐式设置Button.Content
,它等效于:
<Button HorizontalAlignment="Left" Margin="70,136,0,0" Name="Button2" VerticalAlignment="Top">
<Button.Content>
<TextBlock Padding="2" FontSize="16" TextWrapping="NoWrap" Foreground="#FF8787DB" FontWeight="Bold">
Calculate CTR Losses
<LineBreak />
(From FTD Data)
</TextBlock>
</Button.Content>
</Button>
Your original code overlays the TextBlock
over the button, so both of these elements aren't related. 您的原始代码将TextBlock
覆盖在按钮上,因此这两个元素都不相关。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.