Question

I'm using ZoomControl from WPFExtensions. Source code is here.

I've added adorner with OnRender method:

protected override void OnRender(DrawingContext drawingContext)
{
    drawingContext.DrawEllipse(
        new SolidColorBrush(Colors.CornflowerBlue), 
        null, 
        new Point(1292, 100),
        100, 100);   
} 

using 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>

Applying adorner:

public Window1()
{
    InitializeComponent();
    image1.Loaded += loaded;
}

private void loaded(object sender, RoutedEventArgs e)
{
    var adorner = new SplitAdorner(image1);
    AdornerLayer.GetAdornerLayer(image1).Add(adorner);
}

When I drag Image control, my adorner is not moving.

I've tried overriding ArrangeOverride and 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);
}

But no effect. There is not anything in Output window and adorner is not moving.

When I'm zooming - everything is OK though. Adorner changes it's position accordingly to Image control changes.

The problem is in my code or in ZoomControl?

Example app is here.

SOLUTION:

I had to put my canvas into 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>

Description is here.

Was it helpful?

Solution

Ok, i looked into your example app and checked it with snoop. So it seems that the transformation is somehow applied to your adorner aswell, but the visual is not correctly updated. Panning works in fact, its just that your adorner is not properly invalidated. One quick idea is to give your adorner dependency property for zoom, translate x, translate y, and set the property flag "AffectsRender" and bind them from the zoom control to your canvas. Now everytime your zoom control modifies one of these properties, the adorners properties are updated via binding and directly invalidated via the "AffectsRender" flag.

[First answer, but not valid]

Are you applying the transform of the zoom control to your adorner? Because an adorner is not placed on the control, in fact it is registered in the next AdornerDecorator, found upwards beginning on the provided control. My guess is that the only decorator(or layer) found is the default one on the window. Apply the transform of the control to your adorner and it should work. Or you could place an AdornerDecorator inside your Zoomcontrol, but to be honest i'm not sure if this has the desired effect.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top