how data bind union case value within xaml?
currently data-bound value pointing string20 object instead of actual string value union case (i.e. string20) wraps around.
example:
<listview itemssource="{binding modules}" displaymemberpath="author.first" />
author definition:
type name = { first:string20 last:string20 suffix:string20 option } type module = { author:name duration:duration }
xaml:
<window x:class="client.mainwindow" ... xmlns:managemodules="clr-namespace:managemodules;assembly=managemodules"> <window.datacontext> <managemodules:creationviewmodel /> </window.datacontext> <grid> <listview itemssource="{binding modules}" displaymemberpath="author.first" textelement.foreground="lightblue" background="black" /> </grid> </window>
viewmodel:
namespace managemodules ... type creationviewmodel() = inherit viewmodelbase() let name = { first=string20("scott"); last=string20("nimrod"); suffix=none } let duration = { hours=1; minutes=30; seconds=0 } let moduleitem = { author=name; duration=duration } let mutable (_modules:module observablecollection) = observablecollection() _modules.add(moduleitem) member this.modules get() = _modules , set(value) = _modules <- value member this.add moduleitem = _modules.add(moduleitem)
business domain:
module managemodule.entities type duration = { hours:int minutes:int seconds:int } type string20 = string20 of string type name = { first:string20 last:string20 suffix:string20 option } type module = { author:name duration:duration } , section = | introduction of module | conclusion of module | content of module list
my recommendation modify string20
includes additional member plain string
value - , can bind ordinary string
member.
to add member type, can write:
type string20 = | string20 of string member this.value = let (string20(str)) = str
then should able write:
<listview itemssource="{binding modules}" displaymemberpath="author.first.value" />
there more sophisticated ways solve - guess wpf has mechanism specifying transformations happen in bindings behind scenes - adding value
member simple start.
Comments
Post a Comment