2011-07-30 67 views
1

我有2個參數在SharePoint Web部件項目中定義,當用戶從2個組合框中選擇(可瀏覽時將傳遞到Silverlight應用程序中的Application_Startup()屬性)。不知何故,當我在SharePoint網站上加載它時,Silverlight控件無法呈現。在傳入1個參數後,控件將顯示無誤。有任何想法嗎?句法?例子?將2個參數傳遞給Silverlight控件從SharePoint Web項目項目到Silverlight應用程序

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

反正使用

if (_setArticles.Equals("_1_article")) 
{ 
    retrieveOneListboxItemStaffNews(); 
    GetData3(); 
} 
if (_setArticles.Equals("_2_articles")) 
{ 
    retrieveTwoListboxItemStaffNews(); 
    GetData3(); 
} 
if (_setArticles.Equals("_3_articles")) 
{ 
    retrieveThreeListboxItemStaffNews(); 
    GetData3(); 
} 
無論如何,每次都會調用

,否則GetData3()將被調用3次。

+0

感謝您的回覆。你碰巧知道我如何訪問嵌入在數據模板中的文本塊?在線示例並沒有太大幫助,因爲它涉及到在網格中指定x:key? – brainsfrying

相關問題