views:

696

answers:

4

I have a bunch of data points that I would like to two-way bind to points on a canvas.

The points assume larger y values are reflected in an upwards direction like most math graphs.

How do I change the x,y origin of the canvas to the bottom left corner and reverse it's interpretation of the y coordinate?

(I would like to stay in XAML)

A: 

If you use databinding you can use a TypeConvertor, but for that you have to go outside the XAML and you need to know the size of the canvas beforehand.

pb
+1  A: 
<Canvas>
    <Canvas.LayoutTransform>
        <ScaleTransform ScaleX="1" ScaleY="-1" CenterX=".5" CenterY=".5" />
    </Canvas.LayoutTransform>
</Canvas>
qntmfred
Thanks for this, but aren't ScaleX, CentreX, and CenterY redundant?Just using ScaleY="-1" seems to do the trick.Also, others beware that this will also flip any text upside down.
David Smith
yes the other properties are redundant, but it's convention (from what I've seen) to include those properties. And yes, it will flip the text, but if you're just drawing points should be ok. if you need to draw text, you could draw it on a 2nd transparent Canvas that is on top of the graph Canvas
qntmfred
A: 

I'd probably create a custom panel instead of using Canvas and give it the attached properties that make sense for your needs. Here is an example of implementing a custom panel:

http://blog.boschin.it/articles/silverlight-radialpanel.aspx

Something like Canvas is very simple since you don't have to do much in the measure and arrange overrides.

You may also be able to inherit from Canvas and override ArrangeOverride, I haven't tried that but it may work.

Bill Reiss
Bill, you don't say what is wrong with using Canvas?
David Smith
Well I don't see how you can do this with a straight Canvas, if you scale it -1 in the Y everything will be flipped. I guess you could scale all of the elements -1 as well.
Bill Reiss
A: 

I have been searching for exactly this question for last few minutes, but still there is a problem for me, how can i use these lines that you adviced in my xml file? i am not really experienced about using xml, so could someone help?

" "

Sohret