我有以下
<ResourceDictionary
xmlns:vm="clr-namespace:SilverlightApplication1.ViewModels.Controls">
<DataTemplate DataType="vm:CVItemVM" x:Key="viewmodel">
…………
<sdk:DataGrid Grid.Row="1" AutoGenerateColumns="False" Width="820" MaxColumnWidth="395" ItemsSource="{Binding Path=Publications}" Visibility="{Binding Path=Publications.Count, Converter={StaticResource ConverterVisibility2_1}}">
<sdk:DataGrid.ColumnHeaderStyle>
<Style TargetType="sdk:DataGridColumnHeader">
<Setter Property="FontWeight" Value="Bold" />
</Style>
</sdk:DataGrid.ColumnHeaderStyle>
<sdk:DataGrid.Columns>
<sdk:DataGridTextColumn Header="Title" Binding="{Binding Path=Title}" CanUserResize="False" IsReadOnly="True" />
<sdk:DataGridTextColumn Header="Author" Binding="{Binding Path=Author}" CanUserResize="False" IsReadOnly="True" />
<sdk:DataGridTemplateColumn Header="">
<sdk:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button Content="{Binding Path=Id}" Command="{Binding Path=DeleteCommand, Mode=TwoWay}" />
</DataTemplate>
</sdk:DataGridTemplateColumn.CellTemplate>
</sdk:DataGridTemplateColumn>
</sdk:DataGrid.Columns>
</sdk:DataGrid>
我面临的问题是
<Button Content="{Binding Path=Id}" Command="{Binding Path=DeleteCommand, Mode=TwoWay}" />
不触发绑定的命令。
ItemsSource="{Binding Path=Publications}"
指以下(在视图模型中)
public ObservableCollection<PublicationVM> Publications
相同的视图模型暴露
public ICommand DeleteCommand { get; set; }