代码如下所示。当我尝试单击按钮的中间时,您实际上是单击TextBlock而不是触发Button2_click事件。只有当您单击TextBlock外部并仍然在Button内部时,它才会触发事件。
在Button的内容中有两行文本的正确方法是什么。我是StackOverFlow的新手,所以我没有足够的声誉来添加图片。请帮助解决这个问题。感谢您提前帮助。
<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>
答案 0 :(得分:2)
将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>
这将隐式设置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>
您的原始代码会将TextBlock
覆盖在按钮上,因此这些元素都不相关。