views:

116

answers:

1

Hi,

I am developing (using Silvelight 3) an aplication that creates some kind of timeline and places objects on it. For this purpose I need a really large Canvas (up to 2000000 pixels width) with long lines on it, but whenever I create Canvas even 40000 pixels width it behaves very strangely, randomly disappearing.

I have found a post with the description of the exactly same problem on silverlight forums and another one here on the stackoverflow. It seems that is a known problem since silverlight 2, but I can't find any good workaround. Does anybody know such workaround or can check is it still an issue in Silverlight 4?

Thanks in advance.

A: 

One of the responses to the SO question mentions the the problem stems from the representation of points

"Watch out: the maximum size of a Silverlight canvas is 32767 points. This is because the size of UIElements is not stored as floats as it is in WPF, but in 32 bit quantities of which 16 bits form the integer of size and 16 bits form the floating part of it.

There is enough precision but not enough range. One possible solution is to scale all your points into the range allowed as you add them to the canvas. For example, divide by 1024 will get your 2000000 pixels down to a range of ca. 2000, well within the range, and with a prevision of 1/1024, it's well within the precision also. (We are essentially just shifting the entire 32-bit value, integral and fractional part 10 places right, so no loss in precision, but an increased range.)

You may even be able to create custom container that does this mapping for you.

mdma
Unfortunately the scaling is also one of the tasks of my application, i.e. I have to be able to change scaling timeline up 1 second per 100 pixels. So it's not a solution in my case. But thanks for your answer anyway.
Fury
I think you are mixing screen resolution from the abstract co-ordinate space. You can draw on-screen as a transform of the co-ordinates you use. Essentially the co-ordinates are in your logical problem space, and the presentation is screen space. You use a transform to convert form your logical space to screen space. This tackles both your problems, large co-ordinate values and presentation scaling in one. See RenderTransform on UIElement.
mdma
"I think you are mixing screen resolution from the abstract co-ordinate space"Indeed I am. A lot of thanks for this advice. I have already solved my particular problem, but I'll remember about the transformations in the future.
Fury