2010-01-07 57 views
1

我使用緊湊框架3.5和Pocket PC 2003平臺。C#和CF:設計時間屬性

我在寫我的應用程序自定義控制。我希望將某些屬性作爲設計時屬性公開。

它在MSDN描述(http://msdn.microsoft.com/en-us/library/tk67c2t8.aspx)的方式是不實際工作。

我得到:

類型或命名空間名稱「的CategoryAttribute」找不到(是否缺少using指令或程序集引用

我使用智能感知看? 。什麼屬性我可以寫它列出像一些奇怪的事情:

  • EditorBrowsable
  • 德signerCategory
  • 默認值
  • DesignTimeVisible

還有更多。如果我嘗試使用這些這樣:

public partial class Counter : UserControl 
{ 
[EditorBrowsable(EditorBrowsableState.Always)] 
[DesignerCategory("Data")] 
[DesignTimeVisible(true)] 
[DefaultValue(0)] 
public UInt64 theNumber; 

..我得到以下錯誤:

屬性「DesignerCategory」不是 在此聲明類型有效。這是 僅適用於「類」的聲明。

屬性'DesignTimeVisible'不是 對此聲明類型有效。它是 只對'class,interface' 聲明有效。

什麼是使用設計時間屬性的正確方法?

回答

1

這裏真正的問題是你沒有使用屬性;你應該有:

public ulong TheNumber { get; set; } 

private ulong theNumber; 
public ulong TheNumber { 
    get { return theNumber; } 
    set { theNumber = value; } 
} 

重屬性:從本質上講,根本不支持的那些屬性(不存在),緊湊型框架。您引用的MSDN文章是針對「完整」.NET的。如果你看(例如)DisplayNameAttribute它不要求在CF上工作。

屬性等應該已經是可用在設計時設置;你只是不具備調整設計時體驗的能力。

順便說一下,在大多數代碼中,ulong是非常罕見的,但這不是問題。