Edit Title in Silverlight 4

大兔子大兔子 提交于 2019-12-13 15:26:07

问题


We are developing an out-of-browser Silverlight 4 application and want to change the title after the application loads.

Example:

public partial class MainPage : UserControl
{
    public MainPage()
    {
        InitializeComponent();
        this.Loaded += new RoutedEventHandler(MainPage_Loaded);
    }

    public string UserName { get; set; }
    public string VersionNumber { get; set; }

    void MainPage_Loaded(object sender, RoutedEventArgs e)
    {
        string title = string.Format("MyApplication {0} {1} ", this.VersionNumber, this.UserName);

        HtmlPage.Window.Eval(string.Format("document.title='{0}'", title));
    }
}

Three things I have tried:

  1. The above example does not work and throws an InvalidOperationException "The DOM/scripting bridge is disabled." All the references I found, example, said the HTML bridge is disabled in OOB mode.

  2. Create a custom OOB Window, example, but I would prefer a more elegant solution.

  3. Adjust the OutOfBrowserSettings.xml file, but it doesn't appear that I can get access to it after Load.

Any ideas on how to adjust the title after the application has loaded?


回答1:


Unfortunately, the only way to do this is to create a custom OOB Window:

Look here and here for examples.




回答2:


Try setting:

<param name="windowless" value="true"/>

<object id="SilverlightControlApp" data="data:application/x-silverlight-2," type="application/x-silverlight-2"
            width="100%" height="100%">
            <param name="source" value="ClientBin/MyTestApp.Client.xap" />
            <param name="onError" value="onSilverlightError" />
            <param name="background" value="white" />
            <param name="minRuntimeVersion" value="4.0.50826.0" />
             <param name="windowless" value="true"/>
          <%--  <param name="minRuntimeVersion" value="3.0.40818.0" />--%>
            <param name="autoUpgrade" value="true" />
             <a href="http://go.microsoft.com/fwlink/?LinkID=149156&amp;v=4.0.50826.0" style="text-decoration: none">
                <img src="http://go.microsoft.com/fwlink/?LinkId=161376" alt="Get Microsoft Silverlight"
                    style="border-style: none" />
           <%-- <a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=3.0.40818.0" style="text-decoration: none">
                <img src="http://go.microsoft.com/fwlink/?LinkId=161376" alt="Get Microsoft Silverlight"
                    style="border-style: none" />--%>
            </a>
        </object>


来源:https://stackoverflow.com/questions/4018081/edit-title-in-silverlight-4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!