如果您从画布中获取AdornerLayer并绘制装饰器,它仍将绘制在画布之外。
if(newAdorner != null)
{
AdornerLayer.GetAdornerLayer(_drawingCanvas).Add(newAdorner);
_adorners.Add(shapeItem.Uid, newAdorner);
}
<!--<AdornerDecorator x:Name="DrawingAdorner">-->
<Canvas x:Name="DrawingCanvas" Background="Transparent">
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseLeftButtonDown">
<prism:InvokeCommandAction Command="{Binding CanvasLButtonDownCmd}" />
</i:EventTrigger>
<i:EventTrigger EventName="MouseLeftButtonUp">
<prism:InvokeCommandAction Command="{Binding CanvasLButtonUpCmd}" />
</i:EventTrigger>
<i:EventTrigger EventName="MouseMove">
<prism:InvokeCommandAction Command="{Binding CanvasMouseMoveCmd}" />
</i:EventTrigger>
<i:EventTrigger EventName="SizeChanged">
<prism:InvokeCommandAction Command="{Binding CanvasSizeChangedCmd}" />
</i:EventTrigger>
</i:Interaction.Triggers>
</Canvas>
<!--</AdornerDecorator>-->
enter image description here
如何使装饰器只出现在画布区域内?
我试试这个。
<AdornerDecorator x:Name="DrawingAdorner">
<Canvas x:Name="DrawingCanvas" Background="Transparent">
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseLeftButtonDown">
<prism:InvokeCommandAction Command="{Binding CanvasLButtonDownCmd}" />
</i:EventTrigger>
<i:EventTrigger EventName="MouseLeftButtonUp">
<prism:InvokeCommandAction Command="{Binding CanvasLButtonUpCmd}" />
</i:EventTrigger>
<i:EventTrigger EventName="MouseMove">
<prism:InvokeCommandAction Command="{Binding CanvasMouseMoveCmd}" />
</i:EventTrigger>
<i:EventTrigger EventName="SizeChanged">
<prism:InvokeCommandAction Command="{Binding CanvasSizeChangedCmd}" />
</i:EventTrigger>
</i:Interaction.Triggers>
</Canvas>
</AdornerDecorator>
1条答案
按热度按时间monwx1rj1#
代码在修改后正常工作,如下所示。
我还添加了ClipToBounds=“True”。
enter image description here