# Silverlight B3 - Positioning an element within a Canvas

**URL:** <https://www.ruby-forum.com/t/silverlight-b3-positioning-an-element-within-a-canvas/165810>\
**Category:** IronRuby\
**Created:** [April 17, 2009, 6:51pm UTC](https://www.ruby-forum.com/t/silverlight-b3-positioning-an-element-within-a-canvas/165810 "2009-04-17T18:51:34Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![eoin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/f14d63/32.png) [@eoin](https://www.ruby-forum.com/u/eoin)\
**Post date:** [April 17, 2009, 6:51pm UTC](https://www.ruby-forum.com/t/silverlight-b3-positioning-an-element-within-a-canvas/165810/1 "2009-04-17T18:51:34Z")

</div>

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](http://gist.github.com/97116)

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

Thanks.

---

<div class="post-metadata">

**Author:** ![eoin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/f14d63/32.png) [@eoin](https://www.ruby-forum.com/u/eoin)\
**Post date:** [April 17, 2009, 9:38pm UTC](https://www.ruby-forum.com/t/silverlight-b3-positioning-an-element-within-a-canvas/165810/2 "2009-04-17T21:38:35Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![eoin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/f14d63/32.png) [@eoin](https://www.ruby-forum.com/u/eoin)\
**Post date:** [April 17, 2009, 10:09pm UTC](https://www.ruby-forum.com/t/silverlight-b3-positioning-an-element-within-a-canvas/165810/3 "2009-04-17T22:09:44Z")

</div>

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  
\<removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![eoin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/f14d63/32.png) [@eoin](https://www.ruby-forum.com/u/eoin)\
**Post date:** [June 26, 2009, 3:31pm UTC](https://www.ruby-forum.com/t/silverlight-b3-positioning-an-element-within-a-canvas/165810/4 "2009-06-26T15:31:31Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![eoin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/f14d63/32.png) [@eoin](https://www.ruby-forum.com/u/eoin)\
**Post date:** [June 26, 2009, 11:43am UTC](https://www.ruby-forum.com/t/silverlight-b3-positioning-an-element-within-a-canvas/165810/5 "2009-06-26T11:43:22Z")

</div>

Hi,

the issue reported by Eoin a while back is still happening  
([http://gist.github.com/97116](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
