C# 动态更新Silverlight子元素的高度和宽度

C# 动态更新Silverlight子元素的高度和宽度,c#,silverlight-4.0,height,width,C#,Silverlight 4.0,Height,Width,我在silverlight应用程序中遇到了这个特殊的问题。我有一个画布,其中有一些路径元素。我需要在其中一个Path元素上加载另一个UIElement。我有它的代码,它是所有设置 我面临的唯一问题是无法更新这些路径元素的高度和宽度 我想知道我是否可以做这样的事 (Path) this.canvas_name.Children[index].Height = height_of_a_UIElement; (Path) this.canvas_name.Children[index]

我在silverlight应用程序中遇到了这个特殊的问题。我有一个画布,其中有一些路径元素。我需要在其中一个Path元素上加载另一个UIElement。我有它的代码,它是所有设置

我面临的唯一问题是无法更新这些路径元素的高度和宽度

我想知道我是否可以做这样的事

    (Path) this.canvas_name.Children[index].Height = height_of_a_UIElement;
    (Path) this.canvas_name.Children[index].Width  = width_of_a_UIElement;
看起来,即使我投下它,我也无法访问这些属性

谁能帮帮我吗


谢谢

您正在铸造
高度
宽度
属性,而不是
路径
对象。试试这个:

((Path) this.canvas_name.Children[index]).Height = height_of_a_UIElement;
((Path) this.canvas_name.Children[index]).Width  = width_of_a_UIElement;

我真不敢相信我会那样做!非常感谢你,罗布西克洛!!当光标位于方括号之间时,按ctrl+shift+space可检查Visual studio中的数据类型。这将帮助您正确转换