我正在使用来自WPFExtensions的 ZoomControl 。源代码在这里。
我用 OnRender 方法添加了装饰器:
protected override void OnRender(DrawingContext drawingContext)
{
drawingContext.DrawEllipse(
new SolidColorBrush(Colors.CornflowerBlue),
null,
new Point(1292, 100),
100, 100);
}
使用 ZoomControl xaml:
<Controls:ZoomControl x:Name="zoomControl1" Background="AliceBlue">
<Canvas Width="{Binding Path=SModel.Width}" Height="{Binding Path=SModel.Height}">
<Image HorizontalAlignment="Center"
Name="image1" Stretch="Fill"
VerticalAlignment="Center" Source="/Z;component/Images/00000006.jpg"
Margin="0,0,0,0" Canvas.Left="1"
Width="{Binding Path=SModel.Width}" Height="{Binding Path=SModel.Height}">
<Image.LayoutTransform>
<RotateTransform Angle="{Binding Path=SModel.Angle}" />
</Image.LayoutTransform>
</Image>
</Canvas>
</Controls:ZoomControl>
应用装饰器:
public Window1()
{
InitializeComponent();
image1.Loaded += loaded;
}
private void loaded(object sender, RoutedEventArgs e)
{
var adorner = new SplitAdorner(image1);
AdornerLayer.GetAdornerLayer(image1).Add(adorner);
}
当我拖动图像控件时,我的装饰器没有移动。
我尝试过覆盖 ArrangeOverride 和 MeasureOverride:
protected override Size MeasureOverride(Size constraint)
{
Debug.WriteLine("measureoverride");
InvalidateVisual();
return base.MeasureOverride(constraint);
}
protected override Size ArrangeOverride(Size finalSize)
{
Debug.WriteLine("arrangeoverride");
InvalidateVisual();
return base.ArrangeOverride(finalSize);
}
但是没有效果。输出窗口中没有任何内容,并且装饰器没有移动。
当我放大时 - 一切都很好。Adorner 会根据图像控件的变化改变它的位置。
问题出在我的代码中还是在 ZoomControl 中?
示例应用程序在这里。
解决方案:
我不得不将我的画布放入 AdornerDecorator:
<Controls:ZoomControl x:Name="zoomControl1" Background="AliceBlue">
<AdornerDecorator>
<Canvas Width="{Binding Path=SModel.Width}" Height="{Binding Path=SModel.Height}">
<Image HorizontalAlignment="Center"
Name="image1" Stretch="Fill"
VerticalAlignment="Center" Source="/Z;component/Images/00000006.jpg"
Margin="0,0,0,0" Canvas.Left="1"
Width="{Binding Path=SModel.Width}" Height="{Binding Path=SModel.Height}">
<Image.LayoutTransform>
<RotateTransform Angle="{Binding Path=SModel.Angle}" />
</Image.LayoutTransform>
</Image>
</Canvas>
</AdornerDecorator>
</Controls:ZoomControl>
说明在这里。