代码之家  ›  专栏  ›  技术社区  ›  Program.X

从javascript获取xaml ui元素

  •  0
  • Program.X  · 技术社区  · 17 年前

    我试过在谷歌上搜索,但也许我没有形成正确的查询方式,因为我得到了很多无稽之谈和不相关的东西。一个问题可能太简单了。抱歉,我上次做Silverlight已经有一段时间了!

    如果我有一个xaml元素:

    <Image Canvas.Top="128" x:Name="img4_7" Width="180.3" Height="117" Source="monkey1.jpg" Stretch="Fill" Canvas.Left="-3.344" Opacity="0.595"/>
    

    我如何使用x:name在javascript中获得它?我在找像getElementByID()这样的东西,但是要找Silverlight。我几乎想要这样的东西:

    img4_7=rootElement.children.getItem('img4_7');
    

    显然,这行不通!

    我没有使用ASP.NET AJAX。

    谢谢你对这个问题的帮助!

    1 回复  |  直到 17 年前
        1
  •  1
  •   Program.X    17 年前

    算了出来。

    需要使用control.content.findname()。

    这是我的手提行李,让其他人受益:

    handleLoad: function(control, userContext, rootElement) 
    {
        this.control = control;
    
        // Sample event hookup: 
        rootElement.addEventListener("MouseLeftButtonDown", Silverlight.createDelegate(this, this.handleMouseDown));
    
        this.img4_7=control.content.findName("img4_7"); 
    
        if (this.img4_7) {
            this.img4_7.addEventListener("MouseEnter", Silverlight.createDelegate(this,this.handleMouseEnter));
            this.img4_7.addEventListener("MouseLeave",Silverlight.createDelegate(this,this.handleMouseLeave));
    
        }
    
    
    },