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?
Answer: 1
[Display(Order = 6, Name = "CountryLabel", Description = "CountryDescription", ResourceType = typeof(EntityDataStrings))]
Where EntityDataStrings
is a resource file containing values for "CountryLabel"
and "CountryDescription"
.
Answer: 2
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!
by : Davut Gürbüzhttp://stackoverflow.com/users/413032
No comments:
Post a Comment
Send us your comment related to the topic mentioned on the blog