c# - How to bind a text box to a member in data context conditionally? -
i'm not sure if it's possible @ wonder if it's possible bind text box 2 different fields depending on value of third.
suppose have carrier goes origin destination , has status of being on way or having arrived. because of business logic , way customer works want grid of orders this.
#id orgin dest. status 101 b going 102 c d going 103 d going
however, when order id e.g. 102 reaches status, point of destination should viewed in origin column , destination column should empty (or show next stop or whatever else), this.
#id orgin dest. status 101 b going 102 d - done 103 d going
so bind column origin field origin in data context if status going bind field destination if status done.
if it's not possible, how can approach it? forced create new data type maps actual orders viewable orders? or add property view model isn't supported field rather renders value depending on status?
here example of multibinding.
<textbox> <textbox.text> <multibinding converter="{staticresource converternamehere}"> <binding path="text"/> <binding path="text"/> </multibinding> </textbox.text> </textbox>
converter sample:
public class convertername : imultivalueconverter { public object convert(object[] values, type targettype, object parameter, system.globalization.cultureinfo culture) { // check binded values , return string want to. // values array of items binded in xaml. } public object[] convertback(object value, type[] targettypes, object parameter, system.globalization.cultureinfo culture) { throw new notsupportedexception("cannot convert back"); } }
a longer blog article here offers discussion on subject. grid view control, approach analogue using schematic adaptation.
<datagridtextcolumn> <datagridtextcolumn.binding> <multibinding ...> ... </multibinding> </datagridtextcolumn.binding> </datagridtextcolumn>
Comments
Post a Comment