Answered by:
Displaying customized property names in property grid

Question
-
Hi,
I would like to know if it possible to display customized property names in the property grid. This would be both for when the workflow designer is hosted in Visual Studio, and when it is rehosted in a 3rd party application (if there is any difference).
I suspect that the property grid respects an object or type's type descriptor. So, if I provided a custom type descriptor for my activity, then I imagine I could change the display name of what appears in the property. However, will this affect the serialized name of the property in the XAML? My goal is to display localized versions of property names in the property grid. I don't want each different locale to serialize to a different string in the XAML; I would like to serialize an invariant format of the property name, and yet display different property names depending on some localization settings.
Thanks,
Notre
Monday, May 3, 2010 7:04 PM
Answers
-
after comparing, Tim's solution is better.
this is the complete code
AttributeTableBuilder
builder = new AttributeTableBuilder();
builder.AddCustomAttributes(
typeof(Sequence), typeof(Sequence).GetProperty("DisplayName"), new DisplayNameAttribute("test"));
MetadataStore.AddAttributeTable(builder.CreateTable());
new DesignerMetadata().Register();
- Proposed as answer by Ye Yu - MSFT Tuesday, May 4, 2010 12:13 AM
- Marked as answer by Notre Tuesday, May 4, 2010 12:25 AM
Tuesday, May 4, 2010 12:12 AM
All replies
-
are you trying to do something like that you have one property name which is in modelitemproperty, and in the property grid, you want to display another name as the display name of the modelproperty name?
if so, we don't have the direct support API.
what you can do is
1. add an attached property for this activity, put whatever display name you want, and get the value from that model property
2. change the original modelitem property browseattribute as faulse
3. when serialize to XAML, attachedproperty added by user won't get serialized.
is this what you want?
Monday, May 3, 2010 10:48 PM -
this can help you change the browse attribute
AttributeTableBuilder builder = new AttributeTableBuilder();
builder.AddCustomAttributes(typeof(FlowSwitch<string>), typeof(FlowSwitch<string>).GetProperty("Expression"), BrowsableAttribute.No);MetadataStore.AddAttributeTable(builder.CreateTable());
Monday, May 3, 2010 10:58 PM -
You can also use (optionally metadata store and) System.ComponentModel.DisplayNameAttribute to modify how properties display in the property grid.
A non MetadataStore example:
public sealed class CodeActivity1 : CodeActivity { [System.ComponentModel.DisplayName("ExecutionText")] public InArgument<string> Text { get; set; } protected override void Execute(CodeActivityContext context) { string text = context.GetValue(this.Text); } }
Tim- Proposed as answer by Ye Yu - MSFT Tuesday, May 4, 2010 12:13 AM
Monday, May 3, 2010 11:37 PM -
Hi Ye,
"are you trying to do something like that you have one property name which is in modelitemproperty, and in the property grid, you want to display another name as the display name of the modelproperty name?"
I think so, yes. Basically, I want to serialize an activity property in one way, and potentially diplay it in the property grid a different way to support localization.
Based on the steps you provided, I understand that the original model item property won't display in the property grid because of the change to the browsable attribute.
1) Why won't the attached property get serialized? I know I've had attached properties serialized before, in my own code...
2) Will the attached property appear in the property grid? If I understand your suggestion, the idea would be to display the attached property rather than the original model item property, and the attached property will get its value from the model item property. How do I get the attached proeprty to appear in the property grid (using a custom type descriptor for the activity)?
Thanks,
Notre
Monday, May 3, 2010 11:46 PM -
1) Why won't the attached property get serialized? I know I've had attached properties serialized before, in my own code...
can you offer some sample code?
2) Will the attached property appear in the property grid? If I understand your suggestion, the idea would be to display the attached property rather than the original model item property, and the attached property will get its value from the model item property. How do I get the attached proeprty to appear in the property grid (using a custom type descriptor for the activity)?
yes, you understand it correctly.
you can use following code to add attachproperty, and it will display in propertyinspector.
string temp = "hello";
AttachedProperty<string> typeArgumentProperty = new AttachedProperty<string>
{
Name = "hello",
OwnerType = typeof(Sequence),
Getter = (modelItem) => temp,
Setter = (modelItem, value) => temp = value,
IsBrowsable = true
};
designer.Context.Services.GetService<AttachedPropertiesService>().AddProperty(typeArgumentProperty);Tim also offer a good option, you can use System.ComponentModel.DisplayNameAttribute in metadatastore.
Monday, May 3, 2010 11:57 PM -
after comparing, Tim's solution is better.
this is the complete code
AttributeTableBuilder
builder = new AttributeTableBuilder();
builder.AddCustomAttributes(
typeof(Sequence), typeof(Sequence).GetProperty("DisplayName"), new DisplayNameAttribute("test"));
MetadataStore.AddAttributeTable(builder.CreateTable());
new DesignerMetadata().Register();
- Proposed as answer by Ye Yu - MSFT Tuesday, May 4, 2010 12:13 AM
- Marked as answer by Notre Tuesday, May 4, 2010 12:25 AM
Tuesday, May 4, 2010 12:12 AM -
Thanks Tim and Ye! This should do what I want. I didn't know about that attribute.
Cheers,
Notre
Tuesday, May 4, 2010 12:26 AM