2010-05-04 140 views
3

您好我想知道是否有一種方式使用C#獲取當前Silverlight版本的用戶正在運行時,正在開發一個應用程序的客戶端正在開發。獲取當前客戶端Silverlight版本?

它用於記錄目的。

我想知道,如果他們使用瀏覽器上的

回答

2
var dotNetRuntimeVersion = Deployment.Current.RuntimeVersion; 
var silverlightVersion = Environment.Version.ToString(); 

支持:5,4,3

+1

這是不正確的。 Environment.Version顯示CLR的版本,而不是Silverlight:http://msdn.microsoft.com/en-us/library/system.environment.version(v=vs.95).aspx。在我正在開發的當前應用程序中,我運行的是Silverlight 5.1,但是當我檢查Environment.Version時,它顯示5.0。不一樣的東西! – JoeCool 2013-04-25 14:57:23

0

Environment.Version可能從插件版本不同。當我使用Silverlight 4我設法找到與插件版本有所不同的版本,似乎沒有規律性。

有辦法從JS獲取Silverlight插件版本,並且有方法將JS添加到頁面並從Silverlight調用它。因此,與從這裏代碼:http://www.visiblox.com/blog/posts/2010/04/29/determining-silverlight-version-installed/我設法做這種方式:

var pScriptElement = HtmlPage.Document.CreateElement("script"); 
pScriptElement.SetAttribute("type", "text/javascript"); 
pScriptElement.SetProperty("text", "function GetSilverlightVersion(){var parts = Array(\"ver-major\", \"ver-minor\", \"ver-build\", \"ver-revision\");var nav = navigator.plugins[\"Silverlight Plug-In\"];var versionStr = \"\";if (nav) {versionStr = nav.description;} else {if(SilverlightIsInstalledOnIE)versionStr = GetSilverlightVersionOnIE();else versionStr = -1;}return versionStr;}function SilverlightIsInstalledOnIE(version){if(version == null)version = \"1.0\";var AgControl = new ActiveXObject(\"AgControl.AgControl\"); if(AgControl == null)return false;elsereturn AgControl.isVersionSupported(version);}function GetSilverlightVersionOnIE(){var currVersion = Array(1,0,0,0);for(var i=0;i<currVersion.length;i++){currVersion[i] = FindSupportedMaxVersionOnIE(currVersion, i,0,10000000);}return GetVersionString(currVersion);}function GetVersionString(versionArr,currVersion,index){if(index == null)index = -1;var versionStr = \"\";for(var i=0;i<versionArr.length;i++){if(i>0)versionStr += \".\";if(i==index)versionStr +=currVersion;elseversionStr += versionArr[i];}return versionStr;}function FindSupportedMaxVersionOnIE(versionArr, index,bottom,top){if(bottom >= top){return bottom;}var currVersion = bottom;var prevVersion = currVersion;var step = 1;while(currVersion<top){if(SilverlightIsInstalledOnIE(GetVersionString(versionArr,currVersion,index))){prevVersion = currVersion;currVersion += step;step *= 2;}elsereturn FindSupportedMaxVersionOnIE(versionArr, index,prevVersion,currVersion-1)}if(SilverlightIsInstalledOnIE(GetVersionString(versionArr,top,index)))return top;elsereturn FindSupportedMaxVersionOnIE(versionArr, index,prevVersion,top-1)}"); 
HtmlPage.Document.Body.AppendChild(pScriptElement); 

var slVer = HtmlPage.Window.Invoke("GetSilverlightVersion", null); 

這樣我能得到在IE和其他瀏覽器插件的可靠版本。我創建了自己的類來解析和比較版本,以便我可以輕鬆地檢查用戶是否使用修復之前的插件或已知的故障。