tags:

views:

217

answers:

1

I'm using compact framework 3.5 and pocket pc 2003 platform.

I'm writing a custom control for my application. Some properties I want to be exposed as design-time attributes.

The way it is described in MSDN (http://msdn.microsoft.com/en-us/library/tk67c2t8.aspx) is not actually working.

I get:

The type or namespace name 'CategoryAttribute' could not be found (are you missing a using directive or an assembly reference?

I've used Intellisense to see what attributes I can write. It lists some strange things like:

  • EditorBrowsable
  • DesignerCategory
  • DefaultValue
  • DesignTimeVisible

There is more. If I try to use those this way:

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

..i get following errors:

Attribute 'DesignerCategory' is not valid on this declaration type. It is only valid on 'class' declarations.

Attribute 'DesignTimeVisible' is not valid on this declaration type. It is only valid on 'class, interface' declarations.

What is the correct way to use design time attributes?

+1  A: 

The real problem here is that you aren't using properties; you should have:

public ulong TheNumber { get; set; }

or

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

Re the attributes: Essentially, those attributes simply aren't supported (don't exist) for compact-framework. The MSDN article you cite is for "full" .NET. If you look at (for example) DisplayNameAttribute it makes no claim to work on CF.

Properties etc should already be available to set at design-time; you just don't have the same level of ability to tweak the design-time experience.

As an aside, ulong is pretty uncommon in most code, but it isn't a problem.

Marc Gravell