我在AttachedCommandBehavior library here之后为连接的命令模式建模。我的按钮看起来是这样的:WPF - 冻结在不继承DataContext的按钮样式中
<Button>
<Button.Style>
<Style TargetType="{x:Type Button}">
<Setter Property="vms:Attached.Behaviors">
<Setter.Value>
<vms:Behaviors>
<vms:Behavior Event="Click"
Command="{Binding ClickCommand}" />
</vms:Behaviors>
</Setter.Value>
</Setter>
</Style>
</Button.Style>
</Button>
一切都很正常,但在执行上Behavior
设置方法时,该命令是null
。
行为是Freezable
,行为是FreezableCollection<Behavior>
。它似乎不是从Button继承DataContext。
在另一方面,这正常工作:
<Button>
<vms:Attached.Behaviors>
<vms:Behavior Event="Click" Command="{Binding ClickCommand}" />
</vms:Attached.Behaviors>
</Button>
可惜我不能做这种方式,因为我需要使用ItemContainerStyle
对象发出ListViewItem
秒。
是否有某种方法可以在样式中获取DataContext?
您的链接无效。你能编辑和修复吗? – Robaticus 2011-02-05 21:58:35
糟糕,现在已经修好了。 – Snea 2011-02-05 22:06:04