Wpf 裁剪装饰层
我有一个Wpf 裁剪装饰层,wpf,adorner,adornerlayer,Wpf,Adorner,Adornerlayer,我有一个PanZoomImage类,定义如下: <Border Grid.Row="0" Name="border" ClipToBounds="True"> <Canvas Name="canvas"> <Image Name="image" RenderOptions.BitmapScalingMode="NearestNeighbor" Stretch="None" Source="{Binding Path=S
PanZoomImage
类,定义如下:
<Border Grid.Row="0" Name="border" ClipToBounds="True">
<Canvas Name="canvas">
<Image Name="image" RenderOptions.BitmapScalingMode="NearestNeighbor" Stretch="None"
Source="{Binding Path=Source}"
MouseLeftButtonDown="image_MouseLeftButtonDown"
MouseLeftButtonUp="image_MouseLeftButtonUp"
MouseMove="image_MouseMove"
MouseWheel="image_MouseWheel"
Loaded="image_Loaded">
</Image>
</Canvas>
</Border>
我使用此属性向图像添加不同的装饰器。问题在于,当我平移或缩放图像时,aodrners不会被剪裁,而是显示在保存PanZoomImage
的控件之外,如下所示:
我尝试了几种解决方案:
我尝试为边框、画布和图像设置cliptobunds=True
我尝试为AdornerLayer
和每个装饰器分别设置cliptobunds=True
我尝试在Adorner的OnRender中设置剪辑几何体
我还注意到Adorner有一个IsClipEnabled
属性,但当我尝试将其设置为true时,我一直得到一个NullReferenceException(即使Adorner绝对不是null)
谢谢 IsClipEnabled属性可以工作。如果装饰控件没有父控件,则会引发
NullPointerException
。在设置IsClipEnabled
之前,必须将控件放入某个容器中
public AdornerLayer Adorners
{
get
{
return AdornerLayer.GetAdornerLayer(image);
}
}