Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Adorners in WPF
Message
From
19/01/2008 05:44:12
 
 
To
All
General information
Forum:
ASP.NET
Category:
Forms
Title:
Adorners in WPF
Miscellaneous
Thread ID:
01283198
Message ID:
01283198
Views:
75
Hi,

Looks like there's actually no category for this stuff yet. Question is about WPF graphics /C#2008 /.NET 3.5. Below is a snippet lifted from a MS code sample and is the ArrangeOverride for an Adorner:
        protected override Size ArrangeOverride(Size finalSize)
        {
            // desiredWidth and desiredHeight are the width and height of the element that's being adorned.  
            // These will be used to place the ResizingAdorner at the corners of the adorned element.  
            double desiredWidth = AdornedElement.DesiredSize.Width;
            double desiredHeight = AdornedElement.DesiredSize.Height;
            // adornerWidth & adornerHeight are used for placement as well.

            double adornerWidth = this.DesiredSize.Width;
            double adornerHeight = this.DesiredSize.Height;

            topLeft.Arrange(new Rect(-adornerWidth / 2, -adornerHeight / 2, adornerWidth, adornerHeight));
            topRight.Arrange(new Rect(desiredWidth - adornerWidth / 2, -adornerHeight / 2, adornerWidth, adornerHeight));
            bottomLeft.Arrange(new Rect(-adornerWidth / 2, desiredHeight - adornerHeight / 2, adornerWidth, adornerHeight));
            bottomRight.Arrange(new Rect(desiredWidth - adornerWidth / 2, desiredHeight - adornerHeight / 2, adornerWidth, adornerHeight));

            // Return the final size.
            return finalSize;
        }
I don't understand why the example uses Desired.X properties of both the Adorner and its AdornedElement. AFAICS they are always identical at runtime.
The AdornedElement in this case is a Rectangle. topLeft,topRight etc. are Thumbs.

I should mention that other sections of the sample were pretty sloppy and gave erroneous results so I've no great faith in this snippet actually demonstrating best practice...

TIA,
Viv
Next
Reply
Map
View

Click here to load this message in the networking platform