0

I have a dependency property in a custom control which has the following attribute to enable the property to appear under a specific category in the properties viewer with a relevant description.

<Category("Vtl Button Images"), Description("Add an image of your choice or leave blank to utilise the default image supplied.")>
Public Property SaveImage As ImageSource

Now I would like to localise the description element of the attribute so I added a resource string to the project and attempteted to reference it like so.

<Category("Vtl Button Images"), Description(My.Resources.ImageDescription)>
Public Property SaveImage As ImageSource

However this throws an error telling me that a constant expression is required. I get the same error if I try and create a constant set to a resource.

So is it possible to localise the description element of attributes like this and if so how?

Dom Sinclair
  • 2,458
  • 1
  • 30
  • 47
  • Subclass `Description` to take a key (eg `"SaveImage"`) then in the code there use that as a key to look up and return the localized text. Attributes are meta data compiled into the assembly, so trying to swap out text directly based on locale wont work. – Ňɏssa Pøngjǣrdenlarp Dec 05 '15 at 14:53
  • @Plutonix Many thanks, I've stumbled across a c# example of doing something along these lines, Not the easiest of things to follow in it's current guise but I try translating it and see where I get to from there. I assume thought that there would still be a resource at the back of it that gets translated? – Dom Sinclair Dec 05 '15 at 14:59
  • [This?](http://stackoverflow.com/a/7398740/1070452) yes, as per `TODO: lookup from resx` That answer is a little confusing because it is implementing a localized Category and DisplayName too – Ňɏssa Pøngjǣrdenlarp Dec 05 '15 at 15:02
  • To say It's a little confusing would be to put it mildly, however it does provide a starting point from which hopefully I can work. – Dom Sinclair Dec 05 '15 at 15:08
  • It is using the base class to store the localized text. When the object contain that decorated prop is created, rather than "My Description", it looks up the xlation for that and passes it to the base class – Ňɏssa Pøngjǣrdenlarp Dec 05 '15 at 15:20

0 Answers0