RIA 服务/DataForm:如何使用 ReadOnly 和 DataForm一起描述属性

发布于 2024-09-06 11:51:39 字数 938 浏览 5 评论 0原文

我有几种情况,我有一个想要声明为只读的属性,但也给出了如何使用 [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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

拥抱影子 2024-09-13 11:51:39

是的,
我以前遇到过同样的问题,但没有尝试管理。
显示属性和只读属性是密封的,您不能从它们继承。您可以包装它们并创建另一个属性,但您的数据表单现在没有这个属性。所以您不能...

也许您可以在 ReadOnlyTemplate 中做不同的事情

        <dataFormToolkit:DataForm.ReadOnlyTemplate>
          <DataTemplate>
              <Grid>                
            <dataFormToolkit:DataField Label="{Binding ReadOnlyLabel,
                Converter=ReadOnlyOrNotConverter}" >
                <TextBox Text="{Binding Path=ReadOnlyValueEtc, Mode=TwoWay}" />
            </dataFormToolkit:DataField>

希望有帮助,

问候!

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

        <dataFormToolkit:DataForm.ReadOnlyTemplate>
          <DataTemplate>
              <Grid>                
            <dataFormToolkit:DataField Label="{Binding ReadOnlyLabel,
                Converter=ReadOnlyOrNotConverter}" >
                <TextBox Text="{Binding Path=ReadOnlyValueEtc, Mode=TwoWay}" />
            </dataFormToolkit:DataField>

Hope helps,

Regards!

彩扇题诗 2024-09-13 11:51:39
[Display(Order = 6, Name = "CountryLabel", Description = "CountryDescription",
ResourceType = typeof(EntityDataStrings))]

其中 EntityDataStrings 是包含 "CountryLabel""CountryDescription" 值的资源文件。

[Display(Order = 6, Name = "CountryLabel", Description = "CountryDescription",
ResourceType = typeof(EntityDataStrings))]

Where EntityDataStrings is a resource file containing values for "CountryLabel" and "CountryDescription".

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文