Given a data structure of:
type Candidate = SalesRep of SalesRep | Analyst of Analyst
type ScorableCandidate = {
candidate: Candidate ;
mutable comments: string ;
mutable score: int ;
}
and a data grid that wants to be able to display either of the candidates, is it possible to bind (using the WPF binding) to the ScorableCandidate?
<telerik:GridViewDataColumn Header="First Name" DataMemberBinding="{Binding candidate.fname}" IsFilterable="False" Width="100"/>
I am thinking not, as the binding syntax would bneed to be able to deconstruct the type – which I don’t think is possible.
Thx
T
I believe that you shouldn’t have any trouble accessing the
candidatefield of the record type (because record fields appear as standard .NET properties).Regarding the discriminated union – I like the suggestion to use custom type convertors as Juliet suggests. Another simpler option would be to expose the
fnamefield (which is shared by bothSalesRepandAnalystif I understand your example correctly) as a property of theCandidatetype:Then you should be able to use standard WPF binding syntax for binding to properties.