Smith.Patel
Smith.Patel

Reputation: 183

Is it Possible to Bind two Different resource values in the same textbox using Silverlight

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

Answers (3)

tam
tam

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

Inga
Inga

Reputation: 482

I would use 2 text boxes inside stack panel, o create a data template

Upvotes: 2

Richard Szalay
Richard Szalay

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

Related Questions