【发布时间】:2016-02-26 18:01:36
【问题描述】:
我正在尝试为按钮创建一个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-property 是按钮Content 的一部分,将其作为CommandParameter 传递给模板是完全有意义的。
【问题讨论】:
-
不清楚你在问什么,至少对我来说是这样。
-
@FarhanAnam:如何访问绑定
Content的按钮的属性Id-要传递给CommandParameter的属性 -
你问题的最后两行让我很困惑。
标签: c# wpf data-binding controltemplate