RIA 服务/DataForm:如何使用 ReadOnly 和 DataForm一起描述属性
我有几种情况,我有一个想要声明为只读的属性,但也给出了如何使用 [Display(Description="")] 属性计算/设置它的一些解释。如果可能的话,我想在元数据中执行此操作,而不是在数据表单本身中覆盖。
下面是一个示例:
[Display(Description = "Total number of travel hours, calculated as total hrs worked - actual working hrs this month")]
public decimal TravelHours
{
get
{
return this.TotalHrsWorked - this.ActualWorkedHours;
}
}
这不会将描述显示为 DescriptionViewer 当我在 DataForm 中绑定到此属性时DataField。
似乎当我设置 [ReadOnly] 属性时,它隐藏了 DescriptionViewer,甚至在数据表单 xaml 中设置 DescriptionViewerVisibility=Visible 仍然不会改变它。此外,任何计算属性(无设置器)似乎默认强制执行此属性。这有点烦人,因为这些是我真正想向描述查看器显示的内容。
到目前为止,我发现的唯一方法是使该属性不是只读的,并添加一个虚拟设置器(用于计算属性)。这看起来像是一个拼凑。
有什么方法可以在只读属性上显示数据表单/数据字段描述查看器吗?
I have several cases where I have a property that I want to declare readonly, but also give some explanation of how it is calculated/set using the [Display(Description="")] attribute. I would like to do this in the metadata, if possible, rather than override in the dataform itself.
Here's an example:
[Display(Description = "Total number of travel hours, calculated as total hrs worked - actual working hrs this month")]
public decimal TravelHours
{
get
{
return this.TotalHrsWorked - this.ActualWorkedHours;
}
}
This won't show the description as a DescriptionViewer when I bind to this property in a DataForm & DataField.
It seems like when I set the [ReadOnly] attribute it hides the DescriptionViewer, and even setting DescriptionViewerVisibility=Visible in the dataform xaml still doesn't change it. Also, any calculated properties (no setter) seem to have this attribute enforced by default. It's kind of annoying, because these are the ones I really want to show the descriptionviewer for.
The only way around it I have found so far is to make the property not readonly and add a dummy setter (for calculated properties). That seems like a kludge.
Is there any way to show the dataform/datafield descriptionviewer on readonly properties?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,
我以前遇到过同样的问题,但没有尝试管理。
显示属性和只读属性是密封的,您不能从它们继承。您可以包装它们并创建另一个属性,但您的数据表单现在没有这个属性。所以您不能...
也许您可以在 ReadOnlyTemplate 中做不同的事情
希望有帮助,
问候!
Yeah,
I encountered same problem before but didn't try to manage.
Display Attribute and , ReadOnly Attribute's are sealed you can't inherit from them. You may wrap them and create another attribute but your dataform doesn't now this attribute.So you can't...
Maybe you can do different things in ReadOnlyTemplate
Hope helps,
Regards!
其中
EntityDataStrings
是包含"CountryLabel"
和"CountryDescription"
值的资源文件。Where
EntityDataStrings
is a resource file containing values for"CountryLabel"
and"CountryDescription"
.