.net - Implementing a custom Binding -
i have myusercontrol
contains label label
, , bo public person person {get;set;}
.
i want person's name
bind label
this:
("name: {0}", person.name
), in case if person != null
and
("name: {0}", "(none)"
), in case if person == null
more that, if person name changed, label automatically update it.
is there possibility such binding?
"dirty" variant:
private void label_layoutupdated(object sender, eventargs e) { label.content = string.format("name: {0}", _person == null ? "(none)" : _person.name); }
how about:
<stackpanel orientation="horizontal"> <textblock text="name: "/> <textblock text="{binding person.name, fallbackvalue='(none)'}"/> </stackpanel>
this doesn't use label, accomplishes goal.
if needs label, can this:
<label content="{binding person.name, fallbackvalue='(none)'}" contentstringformat="name: {0}"/>
one caveat both approaches text display name: (none)
if binding incorrect (person == null equivalent behavior no property person found).
Comments
Post a Comment