代码之家  ›  专栏  ›  技术社区  ›  Neo42

如何从XAML/Silverlight调用javascript函数并传递值?

  •  1
  • Neo42  · 技术社区  · 17 年前

    但我该如何称呼ShowMsg?或者更准确地说,我如何将值传递给该调用?通常在javascript中,你可以直接去:ShowMsg(500700,“你欠我们钱”);

            <Canvas x:Name="btnLandOnSpace" Background="LightGreen" MouseLeftButtonUp="LandOnSpace"
                Cursor="Hand" Canvas.Top ="0"  Width="70" Height="50"> 
                <TextBlock Text="LandOnSpace"  />
                </Canvas>
    

    function LandOnSpace(sender, e) {  //on server
    if (!ShipAnimateActive && !blnWaitingOnServer) {
        blnWaitingOnServer = true;
        RunServerFunction("/sqgame/getJSLLandOnSpace");
            ShowWaitingBox();
            };
    else {
        alert('Waiting on server.');
    };
    }
    
    
    
    function ShowMsg(SintCost, SintRent , SstrChoiceText) { 
    blnPayChoice = true;    
    intCost = SintCost;     
    intRent = SintRent;     
    strChoiceText = SstrChoiceText;   } 
    

    2 回复  |  直到 11 年前
        1
  •  2
  •   Guillaume Gros    17 年前

    如果你想从Silverlight 2.0调用javascript函数,你可以在系统中使用HtmlPage。窗户。浏览器命名空间。

    var param = new object[] {"some parameter"};
    HtmlPage.Window.Invoke("myfunc",param);
    

    然而,根据您上面的示例,您似乎在使用Silverlight 1.0,其中您的事件处理程序是Javascript,而不是C#或VB。

    您可以在Google App Engine上完美运行Silverlight 2.0应用程序。

    要在2.0中开始开发,请在此处下载Silverlight 2工具: http://www.microsoft.com/downloadS/details.aspx?familyid=C22D6A7B-546F-4407-8EF6-D60C8EE221ED&displaylang=en

    有关如何在Silverlight托管代码和浏览器内的Javascript之间进行通信的一些参考,您可以查看此页面: http://msdn.microsoft.com/en-us/library/cc645076(VS.95).aspx

        2
  •  1
  •   Erik Mork    17 年前

    Silverlight 1.0 docs 。请参阅FindName方法。

    推荐文章