将 2 个参数从 SharePoint Web 部件项目传递到 Silverlight 控件到 Silverlight 应用程序

发布于 2024-11-26 21:12:53 字数 2358 浏览 1 评论 0原文

我在 SharePoint Web 部件项目中定义了 2 个参数,当用户从 2 个组合框(可浏览属性)中进行选择时,这些参数将传递到 Silverlight 应用程序中的 Application_Startup() 中。不知何故,当我将 Silverlight 控件加载到 SharePoint 网站上时,它不会呈现。传入1个参数,控件显示无误。有什么想法吗?句法?例子?

App.xaml.cs:

private void Application_Startup(object sender, StartupEventArgs e)
{
    //testing
    string _setArticles = null;
    string _setLength = null;
    if (e.InitParams != null && e.InitParams.Count >= 1)
    {
        _setArticles = e.InitParams["_setArticles"];
        _setLength = e.InitParams["_setLength"];
    }
    this.RootVisual = new Page(_setArticles, _setLength);
}

Page.xaml.cs:

public Page(string _setArticles, string _setLength)
{
    InitializeComponent();

    //(number of items to display on load)
    if (!string.IsNullOrEmpty(_setArticles) && !string.IsNullOrEmpty(_setLength) )
    {
        if (_setArticles.Equals("_1_article"))                   
            retrieveOneListboxItemStaffNews();
            GetData3();
        if (_setArticles.Equals("_2_articles"))
            retrieveTwoListboxItemStaffNews();
            GetData3();
       if (_setArticles.Equals("_3_articles"))
            retrieveThreeListboxItemStaffNews();
            GetData3();

       //testing
       //send value to method 'fullNameControl_Loaded' (summary length of each ListBox item)                    
       if (_setLength.Equals("_3_lines"))
            m_textBlock.MaxHeight = 40;
       if (_setLength.Equals("_4_lines"))
            m_textBlock.MaxHeight = 50;
       if (_setLength.Equals("_5_lines"))
            m_textBlock.MaxHeight = 65;  
    }
}

SilverlightSecondWebPart.cs:

protected override void CreateChildControls()
{
    base.CreateChildControls();

    //silverlight control
    silverlightControl = new Silverlight();
    silverlightControl.ID = "News";
    silverlightControl.Source = "/ClientBin/News.xap";
    silverlightControl.Width = new System.Web.UI.WebControls.Unit(800);
    silverlightControl.Height = new System.Web.UI.WebControls.Unit(550);


    //testing
    string parameters =  "_setArticles=" + _myEnum + ", " + "_setLength=" + _myEnum2;
    silverlightControl.InitParameters = parameters;
    silverlightControl.MinimumVersion = "2.0";

    Controls.Add(silverlightControl);
}  

I have 2 parameters defined in SharePoint web part project, meant to be passed into Application_Startup() in a Silverlight application when a user selects from 2 combo boxes (browsable properties). Somehow the Silverlight control does not render when i load it on the SharePoint site. With 1 parameter passed in, the control displays without error. Any ideas? Syntax? Examples?

App.xaml.cs:

private void Application_Startup(object sender, StartupEventArgs e)
{
    //testing
    string _setArticles = null;
    string _setLength = null;
    if (e.InitParams != null && e.InitParams.Count >= 1)
    {
        _setArticles = e.InitParams["_setArticles"];
        _setLength = e.InitParams["_setLength"];
    }
    this.RootVisual = new Page(_setArticles, _setLength);
}

Page.xaml.cs:

public Page(string _setArticles, string _setLength)
{
    InitializeComponent();

    //(number of items to display on load)
    if (!string.IsNullOrEmpty(_setArticles) && !string.IsNullOrEmpty(_setLength) )
    {
        if (_setArticles.Equals("_1_article"))                   
            retrieveOneListboxItemStaffNews();
            GetData3();
        if (_setArticles.Equals("_2_articles"))
            retrieveTwoListboxItemStaffNews();
            GetData3();
       if (_setArticles.Equals("_3_articles"))
            retrieveThreeListboxItemStaffNews();
            GetData3();

       //testing
       //send value to method 'fullNameControl_Loaded' (summary length of each ListBox item)                    
       if (_setLength.Equals("_3_lines"))
            m_textBlock.MaxHeight = 40;
       if (_setLength.Equals("_4_lines"))
            m_textBlock.MaxHeight = 50;
       if (_setLength.Equals("_5_lines"))
            m_textBlock.MaxHeight = 65;  
    }
}

SilverlightSecondWebPart.cs:

protected override void CreateChildControls()
{
    base.CreateChildControls();

    //silverlight control
    silverlightControl = new Silverlight();
    silverlightControl.ID = "News";
    silverlightControl.Source = "/ClientBin/News.xap";
    silverlightControl.Width = new System.Web.UI.WebControls.Unit(800);
    silverlightControl.Height = new System.Web.UI.WebControls.Unit(550);


    //testing
    string parameters =  "_setArticles=" + _myEnum + ", " + "_setLength=" + _myEnum2;
    silverlightControl.InitParameters = parameters;
    silverlightControl.MinimumVersion = "2.0";

    Controls.Add(silverlightControl);
}  

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

像极了他 2024-12-03 21:12:53

无论如何使用,

if (_setArticles.Equals("_1_article"))
{
    retrieveOneListboxItemStaffNews();
    GetData3();
}
if (_setArticles.Equals("_2_articles"))
{
    retrieveTwoListboxItemStaffNews();
    GetData3();
}
if (_setArticles.Equals("_3_articles"))
{
    retrieveThreeListboxItemStaffNews();
    GetData3();
}

否则 GetData3() 无论如何都会被调用,每次 3 次。

Anyway use

if (_setArticles.Equals("_1_article"))
{
    retrieveOneListboxItemStaffNews();
    GetData3();
}
if (_setArticles.Equals("_2_articles"))
{
    retrieveTwoListboxItemStaffNews();
    GetData3();
}
if (_setArticles.Equals("_3_articles"))
{
    retrieveThreeListboxItemStaffNews();
    GetData3();
}

otherwise GetData3() will be called anyway, 3 times each time.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文