Reputation: 183
i have two values firstname and lastname i want to display them together as firsname.lastname
how to right the binding path so that i can get both values is it possible to do such things??
Upvotes: 1
Views: 94
Reputation: 1583
A converter could be a good option here
for example it would make sense that you have a Person object in this case. For your textbox bind to the person object and pass it through a converter. the converter could take the values and return your combined string
something like the following
// this would be your convert function inside your converter that implements the IValueConverter interface
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
Person p = value as p;
if (p != null)
{
return string.Format("{0},{1}", p.LastName,p.FirstName);
}
return string.Empty; //or you could show an error maybe...
}
Upvotes: 1
Reputation: 84744
There's not a direct way to do what you're asking.
Create a third property that returns the formatted value and fire a PropertyChanged event for it when either firstname or lastname change.
Upvotes: 3