Pass 2 parameters to Silverlight control from SharePoint web part project into Silverlight application

心不动则不痛 提交于 2019-12-24 10:38:35

问题


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);
}  

回答1:


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.



来源:https://stackoverflow.com/questions/6883323/pass-2-parameters-to-silverlight-control-from-sharepoint-web-part-project-into-s

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