Is it possible to update DisplayNameAttribute of a property at runtime?

Grids for WPF Forum

Posted 1 year ago by Farouk Bouali
Version: 19.1.4
Avatar

Hello,

I made a custom DisplayNameAttribute class, it will retreive the displayname from txlib resource based on the used culture.

public sealed class DisplayNameByResourceAttribute : DisplayNameAttribute
    {
        public DisplayNameByResourceAttribute(string resourceKey) : base(GetResourceValue(resourceKey))
        {
            ResourceKey = resourceKey;
        }

        public string ResourceKey { get; }

        private static string GetResourceValue(string key)
        {
            return Tx.Text(key);
        }
    }

I want the DisplayName is updated at runtime when the txlib culture changes. Any help with this? 

Comments (1)

Posted 1 year ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

Microsoft's DisplayNameAttribute is intended for fixed string values.  Whereas their newer DisplayAttribute (see linked documentation) is intended to pull from the current culture's resources so that it is localizable.  I would suggest using that instead.  We cover that attribute in our documentation on supported attributes too.


Actipro Software Support

The latest build of this product (v24.1.2) was released 2 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.