好吧,经过一番广泛的研究,我发现了如何做到这一点。以下是我所做的,以防将来有人需要我的问题的答案。必须为DSL模型的DesignerExplorer(它在DSLPackage项目中,由modelexplorer.tt文件创建)创建分部类,并在其中输入以下代码:
internal partial class MyDesignerExplorer
{
/// <summary>
/// Override to stop the "Delete" command appearing for
/// Validators.
/// </summary>
protected override void ProcessOnStatusDeleteCommand( MenuCommand command )
{
// Check the selected items to see if they contain
// Validators.
if( this.SelectedElement.GetType()== typeof( Validators ) )
{
// Disable the menu command
command.Enabled = false;
command.Visible = false;
}
else
{
// Otherwise, delegate to the base method.
base.ProcessOnStatusDeleteCommand( command );
}
}
}