【发布时间】:2013-04-02 10:19:02
【问题描述】:
我想创建一个按钮模板,使我的按钮周围有不可点击的区域。 当我按下该区域时,按钮单击事件应该是
这是我的尝试:
<Window x:Class="WpfApplication2.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Button Content="Button" HorizontalAlignment="Left" Margin="214,150,0,0" Name="button1" VerticalAlignment="Top" Click="button1_Click">
<Button.Template>
<ControlTemplate TargetType="Button">
<Border Background="Pink" Padding="25">
<Button Content="{TemplateBinding Content}"></Button>
</Border>
</ControlTemplate>
</Button.Template>
</Button>
</Grid>
</Window>
当我在边框内按下时,button1_Click 方法被调用。
但内部按钮动画未激活。
我希望当我在边框区域内按下时,内部按钮的行为就像被点击一样。
【问题讨论】:
-
为什么你的按钮包含另一个按钮?
-
@dowhilefor 欢迎您提出其他方式来创建具有不可见可点击边距的按钮
-
这很正常。因为内部按钮不接收“点击事件”,因为外部按钮接收。此外,外部按钮
ControlTemplate不包含任何点击动画,因此您不会看到。 -
查看@Snehal 的回答,了解对我来说完美的解决方案。 stackoverflow.com/questions/995757/…