Fury
Fury

Reputation: 71

Problem with large Canvas in Silverlight

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.

Upvotes: 0

Views: 635

Answers (1)

mdma
mdma

Reputation: 57707

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.

Upvotes: 1

Related Questions