none
silverlight中html代码传递问题 RRS feed

  • 问题

  • 比如说再aspx传递个.xml文件  在aspx页面InitParameters="MenuSource=../Menu.xml"

    然后在 app.xaml.cs中:

    private void Application_Startup(object sender, StartupEventArgs e)
            {
                string menuSource = null;
                if (e.InitParams.ContainsKey("MenuSource"))
                {
                    menuSource = e.InitParams["MenuSource"];
                }
                this.RootVisual = new Page(menuSource ?? "Menu.xml");
            }

    的Application_Startup方法内就可以实现往Page.xaml传递

     

    现在请问下  在html里面怎么传递??用JavaScript么???请教高手能够解答

    麻烦说详细点、、对这方面很迷惑、、谢谢

    2009年4月23日 9:04

答案

  • 在静态HTML中要读取XML,就要用JavaScript读取xml,参看下例子
    var url = "NewFile.xml"; 
    String.prototype.Trim = function() { return this.replace(/(^\s*)|(\s*$)/g, ""); }
    
    var xmlDoc;
    
    var moz = (typeof document.implementation != 'undefined') 
    && (typeof document.implementation.createDocument != 'undefined');
    var ie = (typeof window.ActiveXObject != 'undefined');
    
    function importXML(file) {
    
    if (moz) {
    xmlDoc = document.implementation.createDocument("", "doc", null);
    
    } else if (ie) {
    xmlDoc = new ActiveXObject("MSXML2.DOMDocument.3.0");
    xmlDoc.async = false;
    while(xmlDoc.readyState != 4) {};
    }
    
    xmlDoc.load(file);
    }
    importXML(url);
    
    function updateCityState(){
    if (moz) {
    var zip = xmlDoc.getElementsByTagName("zip")[0];
    var city;
    var _city = zip.getElementsByTagName("city")[0].firstChild.nodeValue;
    if (_city) city = _city.Trim();
    
    var state;
    var _state=zip.getElementsByTagName("state")[0].firstChild.nodeValue;
    if(_state) state = _state.Trim();
    
    document.getElementById('city').value = city;
    document.getElementById('state').value = state;
    
    } else if (ie) {
    var city;
    var _city = xmlDoc.selectSingleNode("/zip/city");
    if (_city) city = _city.text;
    var state;
    var _state=xmlDoc.selectSingleNode("/zip/state");
    if(_state) state = _state.text;
    document.getElementById('city').value = city;
    document.getElementById('state').value = state; 
    } 
    }
    
    

    Silverlight Navigation也是解析了XML后再将其赋值的,所以要自己写一下解析你导航的xml函数
    2009年4月24日 4:00
    版主