我正在尝试为按钮创建一个ControlTemplate
,并将CommandParameter
绑定到按钮Content
的某些属性。按钮样式内的内容的访问属性
这目前看起来是这样的:
<Style x:Key="MyStyleKey" TargetType="{x:Type Button}">
<Setter Property="controls:ButtonHelper.CornerRadius" Value="3"/>
// stuck here
<Setter Property="CommandParameter" Value="{Binding ((SomeDataClass)Content).Id}" />
<Setter Property="Template">
<Setter.Value>
// ...
</Setter.Value>
</Setter>
</Style>
被称为
<Button Command="{Binding SetActive}" Content="{Binding SomeDataObject}" Style="{DynamicResource MyStyleKey}" />
通常我会设置CommandParameter
直接
<Button Command="{Binding SetActive}" CommandParameter="{Binding SomeDataObject.Id}" Content="{Binding SomeDataObject}" Style="{DynamicResource MyStyleKey}" />
我的理解模板的是不重复你自己。 从Id
开始 - 属性是按钮Content
的一部分,将它作为CommandParameter
传递给模板是完全有意义的。
目前还不清楚你问什么,至少对我来说。 –
@FarhanAnam:如何访问属性'Id'的按钮绑定'Content'属性被传递给'CommandParameter' – KingKerosin
你问题的最后两行让我困惑。 –