This is a migrated thread and some comments may be shown as answers.
ListView text cell binding
1 Answer 13 Views
This is a migrated thread and some comments may be shown as answers.
Colm
Top achievements
Rank 1
Colm asked on 16 Jun 2017, 02:43 PM

Hi, 

I am using the text cell and I am wondering if I can bind multiple properties in my class to one cell.

 

For example, this is what I currently have;

 

<DataTemplate>

    <telerikListView:ListViewTextCell Text="{Binding client, StringFormat='Client: {0}'}" Detail="{Binding trans_date}" TextColor="Black" DetailColor="LightGray"/>
</DataTemplate>

 

And what I want to do is add another part to the stringformat. EG this: "StringFormat='Client{0} ~ ID: {1}"     - Is this possible, and if it is, can someone give me an example. 

Any assistance is appreciated. Thanks.

1 Answer, 1 is accepted

Sort by
0
Lance | Manager Technical Support
Telerik team
answered on 19 Jun 2017, 03:22 PM
Hello Colm,

You can use a ValueConverter that returns a formatted string that combines multiple property values. 

For example:

<telerikListView:ListViewTextCell Text="{Binding Converter={StaticResource ClientItemConverter}}"
        Detail="{Binding trans_date}"
        TextColor="Black"
        DetailColor="Gray"/>

With that binding, you get the whole object passed to the ValueConverter in the value parameter:

public class ClientItemConverter  : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        var item = value as MyModel;
 
        return $"Client: {item?.client?.name}, ID: {item?.client?.id}";
    }
 
    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}


I've attached a demo with the above approach, here is the result at run-time:




Regards,
Lance | Tech Support Engineer, Sr.
Progress Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Asked by
Colm
Top achievements
Rank 1
Answers by
Lance | Manager Technical Support
Telerik team
Share this question
or