我有一个
我的问题是,由于我正在定义模板化的
在下面的示例中,您可以单击
ControlTemplate
,用于改变多个Button
的外观和行为。我只想让部分Button
可点击并执行绑定的Command
,因此我在ControlTemplate
中添加了一个Button
,并将其绑定到模板的Command
属性��我的问题是,由于我正在定义模板化的
Button
上的Command
绑定,因此无论我点击模板的哪个部分,它都会执行。在下面的示例中,您可以单击
Border
并执行Command
。如何更改它,使得只有在单击模板内的Button
时才执行Command
?<ControlTemplate x:Key="ButtonControlTemplate" TargetType="{x:Type Button}">
<Border BorderThickness="10" BorderBrush="Black">
<Button
Command="{TemplateBinding Command}"
CommandParameter="{TemplateBinding CommandParameter}" >
<ContentPresenter Content="{TemplateBinding Content}" />
</Button>
</Border>
</ControlTemplate>
...
<Button
Command="{Binding Path=SomeViewmodelCommand}"
CommandParameter="{Binding Path=SomeViewmodelCommandParameter}"
Content="Click"
Template="{StaticResource ButtonControlTemplate}" />
我认为我无法将不同的元素(例如Border
)作为模板,因为我仍然需要以某种方式传递Command
,并且附加属性仍会给我相同的行为。