0

在此代码上:

    <DataGrid ItemsSource="{Binding Path=Category.Reports}" 
              AutoGenerateColumns="False" CanUserAddRows="False" CanUserDeleteRows="False"
              Name="_gridReports" SelectedItem="{Binding Report}">
        <DataGrid.RowStyle>
            <Style TargetType="DataGridRow">
                <Setter Property="ContextMenu">
                    <Setter.Value>
                        <ContextMenu DataContext="{Binding Path=PlacementTarget.DataContext, RelativeSource={RelativeSource Self}}">
                            <MenuItem Header="Удалить" Click="OnDeleteClick" 
                                    IsEnabled="{Binding Path=IsDefault, Converter={StaticResource toBoolConverter}}"/>
                            <MenuItem Header="Редактировать" Click="OnEditClick" 
                                    IsEnabled="{Binding Path=IsDefault, Converter={StaticResource toBoolConverter}}" />
                        </ContextMenu>
                    </Setter.Value>
                </Setter>
            </Style>
        </DataGrid.RowStyle>
        <DataGrid.Columns>
            <DataGridTextColumn Binding="{Binding Name}" Header="Название" IsReadOnly="True" />
            <DataGridTextColumn Binding="{Binding Description}" Header="Описание" IsReadOnly="True" />
        </DataGrid.Columns>
    </DataGrid>

编译器几乎创建了该错误消息(从俄语翻译,可能有一些错误):

Invalid value "OnDeleteClick". "Click" is not event for "System.Windows.Controls.DataGridTextColumn"

希望你能帮助我!请

4

1 回答 1

1

把事件变成一种风格

<MenuItem Header="Удалить" IsEnabled="{Binding Path=IsDefault, Converter={StaticResource toBoolConverter}}">
    <MenuItem.Style>
        <Style TargetType="MenuItem">
            <EventSetter Event="Click" Handler="OnDeleteClick" />
        </Style>
    </MenuItem.Style>
</MenuItem>

或使用命令。

于 2012-10-03T23:13:20.833 回答