【发布时间】:2018-07-31 08:10:39
【问题描述】:
例子:
<ListBox Name="List"
ItemsSource="{Binding Items}"
SelectedIndex="{Binding SelectedIndex}">
<ListBox.ItemTemplate>
<DataTemplate>
<DockPanel >
<Button DockPanel.Dock="Left" Content="Show" Command="{Binding ShowCommand}" CommandParameter="{Binding}"/>
<TextBlock Text="{Binding }"/>
</DockPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
点击按钮什么都不做。我试图将命令绑定到DataTemplate 之外的按钮,它可以工作。我还尝试将DataTemplate 中的按钮注册到Click_event,这确实有效。
为什么该命令在 DataTemplate 中不起作用?
【问题讨论】:
标签: wpf button command datatemplate