您的位置:知识库 » .NET技术

在Silverlight 2应用程序中切换用户控件

作者: TerryLee  来源: 博客园  发布时间: 2008-10-09 16:18  阅读: 5772 次  推荐: 0   原文链接   [收藏]  

实现

如下面这段代码,我们设置一个初始化参数InitPage为ContentPage:

<asp:Silverlight ID="Xaml1" runat="server"
     Source="~/ClientBin/SwitchUserControl.xap"
     MinimumVersion="2.0.30523"
     Width="100%" Height="100%"
     InitParameters="InitPage=ContentPage"/>

然后在Application_Startup根据参数不同设置不同的RootVisual:

private void Application_Startup(object sender, StartupEventArgs e)
{
    if (!e.InitParams.ContainsKey("InitPage"))
    {
        this.RootVisual = new DefaultPage();
        return;
    }
    switch (e.InitParams["InitPage"])
    {
        case "MasterPage":
            this.RootVisual = new MasterPage();
            break;
        case "ContentPage":
            this.RootVisual = new ContentPage();
            break;
        default:
            this.RootVisual = new DefaultPage();
            break;
    }
}

现在运行程序后,可以看到起始用户控件为ContentPage,如下图所示:

TerryLee_0102 

0
0
 

.NET技术热门文章

    .NET技术最新文章

      最新新闻

        热门新闻