开发者

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

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.C开发者_运维问答reateChildControls();

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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜