2010-09-08 121 views
1

我試圖將System.Windows.Forms.Label的Font屬性綁定到我的類的屬性(通過窗體設計器)。無法綁定到DataSource上的屬性或列

這是我看到的例外「不能綁定到數據源的屬性或列的HeaderText」

我試圖讓我的類的靜態,並使其暴露靜電性能 - 它並沒有幫助。

生成的代碼看起來是這樣的:

this.WindowTitle.DataBindings.Add(new System.Windows.Forms.Binding("Font", this.fontManagerBindingSource, "HeaderText", true)); 
    // 
    // fontManagerBindingSource 
    // 
    this.fontManagerBindingSource.DataSource = typeof(FontDefinitions.FontManager); 

下面是字體管理器類:

public class FontManager 
    { 
     /// <summary> 
     /// Gets or sets HeaderText. 
     /// </summary> 
     public static Font HeaderText 
     { 
      get { return new Font("Tahoma", 42); } 

     } 
    } 

我在做什麼錯?在什麼情況下不能約束財產?

回答

0

爲什麼你想要屬性是靜態的?它的工作,如果你使它非靜態。

+0

如果我使用非靜態方法,那麼不會拋出異常,但該屬性永遠不會從我的類中讀取。我認爲這是因爲這個類從未實例化過。 – Corvin 2010-09-09 09:39:47

相關問題