【发布时间】:2017-11-21 11:32:53
【问题描述】:
我希望您能够单击删除按钮,然后单击屏幕上的目标注释并删除选定的注释,但是目前发生的只是它删除了所有注释,甚至无法选择一个.
按钮
<StackPanel Orientation="Vertical" VerticalAlignment="Center">
<customControls:ImageButton x:Name="BtnUndo" Height="30" Width="30" ImageSource="..\Images\undo.png" ToolTip="Undo" HorizontalAlignment="Center" VerticalAlignment="Top" Click="BtnUndo_Click" IsEnabled="False" Focusable="False"/>
<customControls:ImageButton x:Name="BtnRedo" Margin="0,2,0,2" Height="30" Width="30" ImageSource="..\Images\redo.png" ToolTip="Redo" HorizontalAlignment="Center" VerticalAlignment="Top" Click="BtnRedo_Click" IsEnabled="False" Focusable="False"/>
<customControls:ImageButton x:Name="BtnClear" Height="30" Width="30" ImageSource="..\Images\clear.png" ToolTip="Clear" HorizontalAlignment="Center" VerticalAlignment="Top" Click="BtnClear_Click" IsEnabled="False" Focusable="False"/>
<customControls:ImageButton x:Name="BtnDeleteTarget" Margin="60,-60,0,2" Height="30" Width="30" ImageSource="..\Images\clear.png" ToolTip="Clear" HorizontalAlignment="Center" VerticalAlignment="Top" Click="DeleteTarget_Click" IsEnabled="True" Focusable="False"/>
</StackPanel>
事件
private void DeleteTarget_Click(object sender, RoutedEventArgs e)
{
Common.Commands.CommandManager.Get().Do(new ClearTargetAnnotation(_annotationManager));
}
命令
{
private AnnotationManager _annotationManager;
private List<Annotation> _annotations;
public ClearTargetAnnotation(AnnotationManager annotationManager)
{
_annotationManager = annotationManager;
_annotations = _annotationManager.GetAll();
}
public void Do()
{
foreach (var annotation in _annotations)
_annotationManager.Remove(annotation);
}
public void Undo()
{
_annotationManager.Set(_annotations);
}
}
}
删除方法
public void Remove( Annotation annotation )
{
Monitor.Enter( _annotations );
_annotations.Remove( annotation );
Monitor.Exit( _annotations );
annotation.OnMoved -= AnnotationMoved;
Draw();
if ( _annotations.Count == 0 )
IsEmptyChanged();
}
【问题讨论】: