开发者

how to set name property dynamically in display attributes in silverlight 4

开发者 https://www.devze.com 2023-03-31 14:04 出处:网络
I want to give name property dynamically in the display attributes for any property. for exam: [Display(Name = \"Test\")]

I want to give name property dynamically in the display attributes for any property.

for exam:

    [Display(Name = "Test")]
    public bool Task1
    {
        get { return this.m_Task1; }
        set
        {
            if (value != this.m_Task1)
            {
                this.m_Task1 = value;
                NotifyPropertyChanged("TaskName");
            }
        }
开发者_开发技巧    }

in that property i want to give the name property dynamically means "Test" and that values will comes from the database. So how can i give the name property dynamically in display attributes while generating the property? Can any one help me to find out the solution?


Try this:

[Display(Name = "Tu edad")]
public int Edad
{
  get { bla, bla...; }
  set { bla, bla...; }
}

public void ChangeEdad()
{
  var TheProperty =
    this.GetType().GetProperties().Where(x => x.Name == "Edad").FirstOrDefault();

  object TheAttribute = 
    TheProperty.GetCustomAttributes(typeof(DisplayAttribute), false)[0];

  DisplayAttribute DA = TheAttribute as DisplayAttribute;
  DA.Name = "Your Age";
}
0

精彩评论

暂无评论...
验证码 换一张
取 消