Silverlight B3 - Positioning an element within a Canvas

Hi there,

I have a very simple hello-world type IronRuby+Silverlight application
based on the AGDLR samples. It consists of a Canvas containing a single
Rectangle. I am attempting to position the Rectangle within the Canvas
as follows:

layout_root.rect.set_value(Canvas.TopProperty, 0.0)

However, this is leading to the following exception:

MethodAccessException:
System.Windows.DependencyObject.SetValue(System.Windows.DependencyProperty,
Double)
MethodAccessException
at System.Reflection.MethodBase.PerformSecurityCheck(Object obj,
RuntimeMethodHandle method, IntPtr parent, UInt32 invocationFlags)

The full trace is at:
http://gist.github.com/97116

What is the preferred method of positioning an element at a Point within
a Canvas?

Thanks.

Hi,

layout_root.rect.set_value(Canvas.TopProperty, 0.0)

I’ve been experimenting the same error a couple of weeks ago. I’m not
sure why these specific property types calls fail.

I’d love to have a solution for that, or at least a workaround.

– Thibaut

I can successfully make the SetValue call from a C# assembly. So I’ve
gotten
around the issue by adding a set_position helper to FrameworkElement
that
calls into a C# helper assembly. Pretty ugly.

On Fri, Apr 17, 2009 at 12:37 PM, Thibaut Barrère
<[email protected]

Hi,

layout_root.rect.set_value(Canvas.TopProperty, 0.0)

not sure if this syntax is supposed to work or not, as I’m just
getting into “attached properties”.

But the following syntax works instead, if someone is trying to achieve
this:

Canvas.SetTop(text_block, 200)

hth,

– Thibaut

Hi,

the issue reported by Eoin a while back is still happening
(http://gist.github.com/97116). If you call this from Silverlight:

layout_root.rect.set_value(Canvas.TopProperty, 0.0)

you’ll get:

MethodAccessException:
System.Windows.DependencyObject.SetValue(System.Windows.DependencyProperty,
Double)

Is there a work-around allowing to set Canvas.TopProperty and other
“static properties” that would currently work, apart from creating a
C# wrapper ?

I went through existing issues in codeplex but it doesn’t seem like
it’s already registered. I can create an issue if it’s a bug.

thoughts ?

– Thibaut