ProvideProperty attribute

J

Joe

Hello.

I have a component that adds a property to other controls similar to
Tooltip. The property is added in the Properties window as expected.

The Get method return a collection which derives from List<>. When the user
clicks the ... for the property the default editor comes up allowing the
user to Add or Remove items. This seems to work fine.

The issue I get is when I look at the code that was added it is not correct.

Here's what I have:
class MyItem
{
private string str1;

public string Str1
{
get
{
return str1;
}
set
{
str1 = value;
}
}

[TypeConverter(typeof(ExpandableObjectConverter))]
class MyList : List<MyItem>
{
}

[ProvideProperty("MyPropertyList", typeof(Control))]
public partial class MyPropertyListComponent : Component,
IExtenderProvider
{
....

public void SetMyPropertyList(Control control, MyList list)
{
if (control == null)
return;

if (Table.ContainsKey(control))
Table[control] = list;
else
Table.Add(control, list);
}

public MyList GetMyPropertyList(Control control)
{

MyList list = null;

if (Table.ContainsKey(control))
list = Table[control];
else
{
list = new MyList();
Table.Add(control, list);
}

return list;
}
}

Here's is how the designer adds the code:
myItem1 = new MyItem();
.....
//
// label1
//
myItem1.Str1 = "Some value";
new MyList().Add(myItem);
....

What happens is that MyPropertyListComponent never gets the items added to
it. I would expect to see something like
MyPropertyListComponent.SetMyPropertyList(label1, myList);

Does this not work with complete classes? If I use a string instead of
MyList then it works. I get
MyPropertyListComponent.SetMyPropertyList(label1, "some string");

Thanks for any help.
Joe
 
J

\Ji Zhou [MSFT]\

Hello Joe,

Thanks for using Microsoft Newsgroup Support Service, my name is Ji Zhou
[MSFT] and I will be working on this issue with you.

Based on my understanding, we are creating a component provide a collection
property for other controls. The problem is that we cannot see the Visual
Studio generate the codes which stores the item. Is my understanding right?
Please correct me if I am off base.

I can see the same behavior as you described. After I use the
DesignerSerializationVisibility attribute to mark the SetMyPropertyList and
GetMyPropertyList. The Visual Studio generates the codes we want, although
in a different manner.

In my side, I use the following codes,
¡­

[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public void SetMyPropertyList(Control control, MyList list)
{
if (control == null)
return;

if (Table.ContainsKey(control))
Table[control] = list;
else
Table.Add(control, list);
}


[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public MyList GetMyPropertyList(Control control)
{

MyList list = null;

if (Table.ContainsKey(control))
list = Table[control] as MyList;
else
{
list = new MyList();
Table.Add(control, list);
}

return list;
}
¡­

And after adding items in the popped up window, I can see the Visual Studio
insert the following codes,

myItem1.Str1 = "Some String";
this.myPropertyListComponent1.GetMyPropertyList(this.label1).Add(myItem1);

It stores the items in a different manner as we expect. The
SetMyPropertyList() does not get called. Instead, it firstly call
GetMyPropertyList to retrieve the list and then call list.Add() method to
store the items. Is this what you want?

Please let me know if you have other questions or concerns on this. And I
will try my best to provide future assistance! Have a nice day!


Best regards,
Ji Zhou ([email protected], remove 'online.')
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://support.microsoft.com/select/default.aspx?target=assistance&ln=en-us.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
J

Joe

Adding the
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
gives me what I need.

Thanks.

""Ji Zhou [MSFT]"" said:
Hello Joe,

Thanks for using Microsoft Newsgroup Support Service, my name is Ji Zhou
[MSFT] and I will be working on this issue with you.

Based on my understanding, we are creating a component provide a
collection
property for other controls. The problem is that we cannot see the Visual
Studio generate the codes which stores the item. Is my understanding
right?
Please correct me if I am off base.

I can see the same behavior as you described. After I use the
DesignerSerializationVisibility attribute to mark the SetMyPropertyList
and
GetMyPropertyList. The Visual Studio generates the codes we want, although
in a different manner.

In my side, I use the following codes,
¡­

[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public void SetMyPropertyList(Control control, MyList list)
{
if (control == null)
return;

if (Table.ContainsKey(control))
Table[control] = list;
else
Table.Add(control, list);
}


[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public MyList GetMyPropertyList(Control control)
{

MyList list = null;

if (Table.ContainsKey(control))
list = Table[control] as MyList;
else
{
list = new MyList();
Table.Add(control, list);
}

return list;
}
¡­

And after adding items in the popped up window, I can see the Visual
Studio
insert the following codes,

myItem1.Str1 = "Some String";
this.myPropertyListComponent1.GetMyPropertyList(this.label1).Add(myItem1);

It stores the items in a different manner as we expect. The
SetMyPropertyList() does not get called. Instead, it firstly call
GetMyPropertyList to retrieve the list and then call list.Add() method to
store the items. Is this what you want?

Please let me know if you have other questions or concerns on this. And I
will try my best to provide future assistance! Have a nice day!


Best regards,
Ji Zhou ([email protected], remove 'online.')
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://support.microsoft.com/select/default.aspx?target=assistance&ln=en-us.
==================================================
This posting is provided "AS IS" with no warranties, and confers no
rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top