从属性名称/描述属性标记文本 [英] Label Text from Property Name/Description Attribute

查看:97
本文介绍了从属性名称/描述属性标记文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



好​​的,所以我在Google上找不到任何可以帮助我的东西(虽然我不确定我是不是寻找合适的东西,如果不是我道歉)。



我的问题是,



如果我有这样的视图模型:



Hi Guys,

Okay, so I've not managed to find anything to help me with this on Google (although I'm not sure I have been searching for the right thing, if not I apologize).

My question is,

If I have a view model like such:

internal class NewDataEntriesViewModel
{
    private CRCSubmissionDataEntry m_Entries;
   
    public NewDataEntriesViewModel(CRCSubmissionDataEntry; dataEntries)
    {
            m_Entries = dataEntries;
    }

    #region Properties
    [Description("Entry Name")]
    Public string EntryName
    {
       get {return m_EntryName;}
    }
    #endregion

}





在我对此ViewModel的View中,如何将标签绑定到我的属性上的Description属性?

这是否可能?



谢谢。



In my View for this ViewModel, how can I bind a label to the Description attribute on my property?
Is this even possible?

Thanks.

推荐答案

是的,这是可能的。你可以使用Reflection做到这一点。检查这个



http://msdn.microsoft.com/en-us/library/aa288454(v = vs.71).aspx [ ^ ]
Yes, it is possible. You can do it using Reflection. Check this

http://msdn.microsoft.com/en-us/library/aa288454(v=vs.71).aspx[^]


我终于找到了解决方案!



以下主题提供了有关如何创建用于数据绑定的转换器的详细信息。它可以很容易地增强到不同类型的属性,但是它的描述属性很难编码,这完全符合我的要求。



这部分归结为Syed的关于帮助我找到它的反思的评论。



链接:



绑定到Propertys属性 [< a href =http://social.msdn.microsoft.com/Forums/vstudio/en-US/11573135-d448-4aed-a0f9-289dabc0eb75/binding-to-a-propertys-attributetarget =_ blanktitle =新窗口> ^ ]
I finally found a solution!

The following thread gives details on how to create a Converter to use with the databinding. It could easily be enhanced to to different types of attributes, however it is hard coded for the description attribute which is perfect for my requirement.

It was partial down to Syed's comment about reflection that helped me find it.

Link:

Binding to a Propertys Attribute[^]


这篇关于从属性名称/描述属性标记文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆