custom display name of property

Oct 11, 2010 at 3:00 AM

hi

I add a property DisplayName,may be help

 

1.WPG/PropertyGrid.cs  

        #region add by singba

        public static string LangCode { get; set; }

        public static  Func<string, string, string> FuncGetLangText { get; set; }

        internal static string GetLangText(string name, string defaultValue)
        {
            if (FuncGetLangText == null)
            {
                return defaultValue;
            }
            else
            {
                string value=FuncGetLangText(name, LangCode);
                return string.IsNullOrEmpty(value) ? defaultValue:value;
            }
        }

        /*sample code       
            WPG.PropertyGrid.LangCode = "zh-CN";
            WPG.PropertyGrid.FuncGetLangText = GetLangText;

            public static string GetLangText(string name, string langCode)
            {
                System.Resources.ResourceManager rManager = LangText.ResourceManager;
                string value= rManager.GetString(name, GetCulture(langCode));
                return string.IsNullOrEmpty(value) ? string.Empty : value;
            }

            public static System.Globalization.CultureInfo GetCulture(string name)
            {
                return new System.Globalization.CultureInfo(name);
            }
        */
        #endregion

2.  WPG/Data/Property.cs

add displayname property

        public string DisplayName
        {
            get
            {
                string displayName=_property.DisplayName ?? _property.Name;
                return PropertyGrid.GetLangText(displayName, displayName);
            }
        }

3.WPG/Themes/VisualStudio/WPGTemplates.xaml

line 30: Text="{Binding Mode=OneTime, Path=Name}"> 

 change to:

Text="{Binding Mode=OneTime, Path=DisplayName}">